From 37fb5ffa29322d67633a6aed56b3d8ceede33d09 Mon Sep 17 00:00:00 2001 From: Tom Spilman Date: Mon, 20 May 2024 08:17:43 -0500 Subject: [PATCH] WIP on native wrapper and generator. --- MonoGame.Framework.Native.sln | 47 +- .../Platform/Native/ConstantBuffer.Native.cs | 36 +- .../Platform/Native/GraphicsDevice.Native.cs | 97 +- MonoGame.Framework/Platform/Native/Interop.cs | 83 +- .../MonoGame.Generator.CTypes/EnumWritter.cs | 50 +- .../PInvokeWritter.cs | 156 ++ Tools/MonoGame.Generator.CTypes/Program.cs | 63 +- .../StructWritter.cs | 92 +- Tools/MonoGame.Generator.CTypes/Util.cs | 32 +- src/monogame/include/csharp_GameWrapper.h | 20 + src/monogame/include/csharp_MGG.h | 31 + src/monogame/include/csharp_common.h | 29 +- src/monogame/include/csharp_enums.h | 1986 +---------------- src/monogame/include/csharp_structs.h | 14 + src/monogame/null_device/MGG.cpp | 111 + src/monogame/null_device/null_device.vcxproj | 146 ++ .../null_device/null_device.vcxproj.filters | 28 + 17 files changed, 957 insertions(+), 2064 deletions(-) create mode 100644 Tools/MonoGame.Generator.CTypes/PInvokeWritter.cs create mode 100644 src/monogame/include/csharp_GameWrapper.h create mode 100644 src/monogame/include/csharp_MGG.h create mode 100644 src/monogame/include/csharp_structs.h create mode 100644 src/monogame/null_device/MGG.cpp create mode 100644 src/monogame/null_device/null_device.vcxproj create mode 100644 src/monogame/null_device/null_device.vcxproj.filters diff --git a/MonoGame.Framework.Native.sln b/MonoGame.Framework.Native.sln index b9056129fc2..3ce98556111 100644 --- a/MonoGame.Framework.Native.sln +++ b/MonoGame.Framework.Native.sln @@ -3,31 +3,68 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Native", "MonoGame.Framework\MonoGame.Framework.Native.csproj", "{56BA741D-6AF1-489B-AB00-338DE11B1D32}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGame.Framework.Native", "MonoGame.Framework\MonoGame.Framework.Native.csproj", "{56BA741D-6AF1-489B-AB00-338DE11B1D32}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{65B3DC17-24BA-4C39-810F-E371AC48199A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Generator.CTypes", "Tools\MonoGame.Generator.CTypes\MonoGame.Generator.CTypes.csproj", "{74F12E34-D96B-4EC1-A218-BAFC83DC6220}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGame.Generator.CTypes", "Tools\MonoGame.Generator.CTypes\MonoGame.Generator.CTypes.csproj", "{74F12E34-D96B-4EC1-A218-BAFC83DC6220}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "null_device", "src\monogame\null_device\null_device.vcxproj", "{3482DDFE-A5BE-4261-868F-A269F2B20DAC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|x64.ActiveCfg = Debug|Any CPU + {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|x64.Build.0 = Debug|Any CPU + {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|x86.ActiveCfg = Debug|Any CPU + {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Debug|x86.Build.0 = Debug|Any CPU {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|Any CPU.ActiveCfg = Release|Any CPU {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|Any CPU.Build.0 = Release|Any CPU + {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|x64.ActiveCfg = Release|Any CPU + {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|x64.Build.0 = Release|Any CPU + {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|x86.ActiveCfg = Release|Any CPU + {56BA741D-6AF1-489B-AB00-338DE11B1D32}.Release|x86.Build.0 = Release|Any CPU {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|x64.ActiveCfg = Debug|Any CPU + {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|x64.Build.0 = Debug|Any CPU + {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|x86.ActiveCfg = Debug|Any CPU + {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Debug|x86.Build.0 = Debug|Any CPU {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|Any CPU.ActiveCfg = Release|Any CPU {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|Any CPU.Build.0 = Release|Any CPU + {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|x64.ActiveCfg = Release|Any CPU + {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|x64.Build.0 = Release|Any CPU + {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|x86.ActiveCfg = Release|Any CPU + {74F12E34-D96B-4EC1-A218-BAFC83DC6220}.Release|x86.Build.0 = Release|Any CPU + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Debug|Any CPU.ActiveCfg = Debug|x64 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Debug|Any CPU.Build.0 = Debug|x64 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Debug|x64.ActiveCfg = Debug|x64 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Debug|x64.Build.0 = Debug|x64 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Debug|x86.ActiveCfg = Debug|Win32 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Debug|x86.Build.0 = Debug|Win32 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Release|Any CPU.ActiveCfg = Release|x64 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Release|Any CPU.Build.0 = Release|x64 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Release|x64.ActiveCfg = Release|x64 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Release|x64.Build.0 = Release|x64 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Release|x86.ActiveCfg = Release|Win32 + {3482DDFE-A5BE-4261-868F-A269F2B20DAC}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {74F12E34-D96B-4EC1-A218-BAFC83DC6220} = {65B3DC17-24BA-4C39-810F-E371AC48199A} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CDA9FB22-5A50-47C6-B732-CE09AC673DCA} + EndGlobalSection EndGlobal diff --git a/MonoGame.Framework/Platform/Native/ConstantBuffer.Native.cs b/MonoGame.Framework/Platform/Native/ConstantBuffer.Native.cs index 509b51b4522..fcd806f3e5d 100644 --- a/MonoGame.Framework/Platform/Native/ConstantBuffer.Native.cs +++ b/MonoGame.Framework/Platform/Native/ConstantBuffer.Native.cs @@ -2,22 +2,52 @@ // This file is subject to the terms and conditions defined in // file 'LICENSE.txt', which is part of this source code package. +using MonoGame.Interop; +using System; +using System.Collections.Generic; +using System.Reflection.Metadata; +using System.Runtime.InteropServices; + namespace Microsoft.Xna.Framework.Graphics; internal partial class ConstantBuffer { - private void PlatformInitialize() - { + internal unsafe MGG_Buffer* Handle; + private unsafe void PlatformInitialize() + { + Handle = MGG.Buffer_Create(GraphicsDevice.Handle, _buffer.Length); } private void PlatformClear() { + // TODO: What is this for? + throw new NotImplementedException(); + } + + internal unsafe void PlatformApply(GraphicsDevice device, ShaderStage stage, int slot) + { + if (Handle == null) + PlatformInitialize(); + + if (_dirty) + { + fixed (byte* data = &_buffer[0]) + MGG.Buffer_SetData(GraphicsDevice.Handle, ref Handle, 0, data, _buffer.Length, true); + _dirty = false; + } + MGG.GraphicsDevice_BindConstantBuffer(GraphicsDevice.Handle, stage, slot, Handle); } - internal void PlatformApply(GraphicsDevice device, ShaderStage stage, int slot) + protected override unsafe void Dispose(bool disposing) { + if (disposing && Handle != null) + { + MGG.Buffer_Destroy(GraphicsDevice.Handle, Handle); + Handle = null; + } + base.Dispose(disposing); } } diff --git a/MonoGame.Framework/Platform/Native/GraphicsDevice.Native.cs b/MonoGame.Framework/Platform/Native/GraphicsDevice.Native.cs index 83fd2716981..fe3f6219069 100644 --- a/MonoGame.Framework/Platform/Native/GraphicsDevice.Native.cs +++ b/MonoGame.Framework/Platform/Native/GraphicsDevice.Native.cs @@ -2,23 +2,96 @@ // This file is subject to the terms and conditions defined in // file 'LICENSE.txt', which is part of this source code package. +using MonoGame.Interop; using System; +using System.Collections.Generic; + namespace Microsoft.Xna.Framework.Graphics; + public partial class GraphicsDevice { - private void PlatformSetup() + internal unsafe MGG_GraphicsDevice* Handle; + + internal Texture2D DefaultTexture; + + private int _currentFrame; + + private unsafe List> _disposeTexturesNextFrame = new List>(); + private unsafe List> _disposeTexturesThisFrame = new List>(); + + private unsafe void PlatformSetup() { + Handle = MGG.GraphicsDevice_Create(); + + // Get the device caps. + MGG_GraphicsDevice_Caps caps; + MGG.GraphicsDevice_GetCaps(Handle, out caps); + MaxTextureSlots = caps.MaxTextureSlots; + MaxVertexTextureSlots = caps.MaxVertexTextureSlots; + _maxVertexBufferSlots = caps.MaxVertexBufferSlots; } - private void PlatformInitialize() + private unsafe void PlatformInitialize() { + MGG.GraphicsDevice_ResetBackbuffer(Handle, + PresentationParameters.BackBufferWidth, + PresentationParameters.BackBufferHeight, + PresentationParameters.BackBufferFormat, + PresentationParameters.DepthStencilFormat); + + _currentFrame = -1; + + // Setup the default texture. + DefaultTexture = new Texture2D(this, 2, 2); + DefaultTexture.SetData(new[] { Color.Black, Color.Black, Color.Black, Color.Black }); } - private void OnPresentationChanged() + private unsafe void OnPresentationChanged() { + // Finish any frame that is currently rendering. + if (_currentFrame > -1) + MGG.GraphicsDevice_Present(Handle, _currentFrame); + + // Now resize the back buffer. + MGG.GraphicsDevice_ResetBackbuffer( + Handle, + PresentationParameters.BackBufferWidth, + PresentationParameters.BackBufferHeight, + PresentationParameters.BackBufferFormat, + PresentationParameters.DepthStencilFormat); + + // Begin a new frame it if was previously rendering. + if (_currentFrame > -1) + { + _currentFrame = -1; + BeginFrame(); + } + } + + private unsafe void BeginFrame() + { + if (_currentFrame > -1) + return; + + // Start the command buffer now. + _currentFrame = MGG.GraphicsDevice_BeginFrame(Handle); + + // We must reapply all the state on a new command buffer. + _scissorRectangleDirty = true; + _blendFactorDirty = true; + _blendStateDirty = true; + _pixelShaderDirty = true; + _vertexShaderDirty = true; + _depthStencilStateDirty = true; + _indexBufferDirty = true; + _rasterizerStateDirty = true; + _vertexBuffersDirty = true; + //_lastNvnBuffer = IntPtr.Zero; + Textures.Dirty(); + SamplerStates.Dirty(); } private void PlatformClear(ClearOptions options, Vector4 color, float depth, int stencil) @@ -30,8 +103,24 @@ private void PlatformDispose() { } - private void PlatformPresent() + private unsafe void PlatformPresent() { + if (_currentFrame < 0) + return; + + MGG.GraphicsDevice_Present(Handle, _currentFrame); + _currentFrame = -1; + + for (int i = 0; i < _disposeTexturesThisFrame.Count; i++) + { + var texture = _disposeTexturesThisFrame[i].Ptr; + MGG.Texture_Destroy(Handle, texture); + } + _disposeTexturesThisFrame.Clear(); + + var temp = _disposeTexturesThisFrame; + _disposeTexturesThisFrame = _disposeTexturesNextFrame; + _disposeTexturesNextFrame = temp; } private void PlatformSetViewport(ref Viewport value) diff --git a/MonoGame.Framework/Platform/Native/Interop.cs b/MonoGame.Framework/Platform/Native/Interop.cs index 14f4c0ef5e6..20b2862395a 100644 --- a/MonoGame.Framework/Platform/Native/Interop.cs +++ b/MonoGame.Framework/Platform/Native/Interop.cs @@ -1,15 +1,92 @@ +using Microsoft.Xna.Framework.Graphics; +using System.Runtime.CompilerServices; +using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; namespace MonoGame.Interop; -internal readonly struct GamePtr { } +internal readonly struct Game { } -internal readonly struct GameWindowPtr { } +internal readonly struct GameWindow { } internal static unsafe partial class GameWrapper { [LibraryImport("monogame", StringMarshalling = StringMarshalling.Utf8)] - public static partial void MG_GW_SetAllowUserResizing(GamePtr* game, GameWindowPtr* gameWindow, [MarshalAs(UnmanagedType.U1)] bool allowuserresizing); + public static partial void MG_GW_SetAllowUserResizing(Game* game, GameWindow* gameWindow, [MarshalAs(UnmanagedType.U1)] bool allowuserresizing); } + +internal struct PtrTo +{ + public unsafe T* Ptr; +} + +internal readonly struct MGG_GraphicsDevice { } +internal readonly struct MGG_Buffer { } +internal readonly struct MGG_Texture { } + +internal struct MGG_GraphicsDevice_Caps +{ + public int MaxTextureSlots; + public int MaxVertexTextureSlots; + public int MaxVertexBufferSlots; +} + +internal static unsafe partial class MGG +{ + #region GraphicsDevice + + [LibraryImport("monogame", EntryPoint = "MGG_GraphicsDevice_Create", StringMarshalling = StringMarshalling.Utf8)] + public static partial MGG_GraphicsDevice* GraphicsDevice_Create(); + + [LibraryImport("monogame", EntryPoint = "MGG_GraphicsDevice_GetCaps", StringMarshalling = StringMarshalling.Utf8)] + public static partial void GraphicsDevice_GetCaps(MGG_GraphicsDevice* device, out MGG_GraphicsDevice_Caps caps); + + [LibraryImport("monogame", EntryPoint = "MGG_GraphicsDevice_ResetBackbuffer", StringMarshalling = StringMarshalling.Utf8)] + public static partial void GraphicsDevice_ResetBackbuffer(MGG_GraphicsDevice* device, int width, int height, SurfaceFormat color, DepthFormat depth); + + [LibraryImport("monogame", EntryPoint = "MGG_GraphicsDevice_BeginFrame", StringMarshalling = StringMarshalling.Utf8)] + public static partial int GraphicsDevice_BeginFrame(MGG_GraphicsDevice* device); + + [LibraryImport("monogame", EntryPoint = "MGG_GraphicsDevice_Present", StringMarshalling = StringMarshalling.Utf8)] + public static partial void GraphicsDevice_Present(MGG_GraphicsDevice* device, int currentFrame); + + [LibraryImport("monogame", EntryPoint = "MGG_GraphicsDevice_BindConstantBuffer", StringMarshalling = StringMarshalling.Utf8)] + public static partial void GraphicsDevice_BindConstantBuffer(MGG_GraphicsDevice* device, ShaderStage stage, int slot, MGG_Buffer* buffer); + + #endregion + + #region Buffer + + [LibraryImport("monogame", EntryPoint = "MGG_Buffer_Create", StringMarshalling = StringMarshalling.Utf8)] + public static partial MGG_Buffer* Buffer_Create(MGG_GraphicsDevice* device, int length); + + [LibraryImport("monogame", EntryPoint = "MGG_Buffer_SetData", StringMarshalling = StringMarshalling.Utf8)] + public static partial void Buffer_SetData( + MGG_GraphicsDevice* game, + ref MGG_Buffer* buffer, + int offset, + byte* data, + int length, + [MarshalAs(UnmanagedType.U1)] + bool discard); + + [LibraryImport("monogame", EntryPoint = "MGG_Buffer_Destroy", StringMarshalling = StringMarshalling.Utf8)] + public static partial void Buffer_Destroy(MGG_GraphicsDevice* device, MGG_Buffer* buffer); + + #endregion + + #region Texture + + [LibraryImport("monogame", EntryPoint = "MGG_Texture_Create", StringMarshalling = StringMarshalling.Utf8)] + public static partial MGG_Texture* Texture_Create(MGG_GraphicsDevice* device, SurfaceFormat format, int width, int height, int levels); + + + [LibraryImport("monogame", EntryPoint = "MGG_Texture_Destroy", StringMarshalling = StringMarshalling.Utf8)] + public static partial void Texture_Destroy(MGG_GraphicsDevice* device, MGG_Texture* texture); + + #endregion +} + + diff --git a/Tools/MonoGame.Generator.CTypes/EnumWritter.cs b/Tools/MonoGame.Generator.CTypes/EnumWritter.cs index 93ec0cd5073..254bff58f03 100644 --- a/Tools/MonoGame.Generator.CTypes/EnumWritter.cs +++ b/Tools/MonoGame.Generator.CTypes/EnumWritter.cs @@ -1,11 +1,16 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System; using System.Text; namespace MonoGame.Generator.CTypes; class EnumWritter { + private readonly Dictionary _types; private readonly StringBuilder _outputText; - private readonly Dictionary _duplicateChecker; public EnumWritter() { @@ -21,39 +26,34 @@ public EnumWritter() """); - _duplicateChecker = []; + + _types = []; } - public static bool IsValid(Type type) + private static bool IsValid(Type type) { return type.IsEnum && !type.IsNested; } - public bool Append(Type type) + public bool TryAppend(Type type) { if (!IsValid(type)) return false; - if (_duplicateChecker.TryGetValue(type.Name, out string? dupFullName)) - { - if (type.FullName != type.FullName) - { - Console.WriteLine($""" - WARNING: Duplicate enum name for {type.Name}: - - {type.FullName} - - {dupFullName} + if (_types.ContainsKey(type.Name)) + return true; - """); - } + _types.Add(type.Name, type); + return true; + } - return false; - } - + private void Generate(Type type) + { var enumValues = Enum.GetValues(type); // Write all values to output _outputText.AppendLine($$""" - enum CS{{type.Name}} : {{Util.GetCEnumType(Enum.GetUnderlyingType(type).ToString())}} + enum {{Util.GetCTypeOrEnum(type)}} : {{Util.GetCType(Enum.GetUnderlyingType(type))}} { """); foreach (var enumValue in enumValues) @@ -66,10 +66,10 @@ enum CS{{type.Name}} : {{Util.GetCEnumType(Enum.GetUnderlyingType(type).ToString """); _outputText.AppendLine($$""" - class ECS{{type.Name}} + class E{{Util.GetCTypeOrEnum(type)}} { public: - static const char* ToString(CS{{type.Name}} enumValue) + static const char* ToString({{Util.GetCTypeOrEnum(type)}} enumValue) { switch (enumValue) { @@ -86,10 +86,14 @@ class ECS{{type.Name}} }; """); + } - _duplicateChecker.Add(type.Name, type.FullName!); - return true; + public void Flush(string dirPath) + { + foreach (var pair in _types) + Generate(pair.Value); + + File.WriteAllText(Path.Combine(dirPath, "csharp_enums.h"), _outputText.ToString()); } - public void Flush(string dirPath) => File.WriteAllText(Path.Combine(dirPath, "csharp_enums.h"), _outputText.ToString()); } diff --git a/Tools/MonoGame.Generator.CTypes/PInvokeWritter.cs b/Tools/MonoGame.Generator.CTypes/PInvokeWritter.cs new file mode 100644 index 00000000000..d7390af2f99 --- /dev/null +++ b/Tools/MonoGame.Generator.CTypes/PInvokeWritter.cs @@ -0,0 +1,156 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System.ComponentModel; +using System.Reflection; +using System.Reflection.Metadata; +using System.Runtime.InteropServices; +using System.Text; +using System.Runtime.CompilerServices; + +namespace MonoGame.Generator.CTypes; + +class PinvokeWritter +{ + private readonly string _name; + + private readonly StringBuilder _outputText; + + private readonly Dictionary _handles; + + private readonly List _methods; + + private EnumWritter _enumWritter; + + private StructWritter _structWritter; + + public PinvokeWritter(Type type, StructWritter structWritter, EnumWritter enumWritter) + { + _name = type.Name; + _enumWritter = enumWritter; + _structWritter = structWritter; + + _outputText = new StringBuilder($""" + // MonoGame - Copyright (C) The MonoGame Team + // This file is subject to the terms and conditions defined in + // file 'LICENSE.txt', which is part of this source code package. + + // + // This code is auto generated, don't modify it by hand. + // To regenerate it run: Tools/MonoGame.Generator.CTypes + // + + #pragma once + + #include "csharp_common.h" + #include "csharp_enums.h" + #include "csharp_structs.h" + + + + """) + { + + }; + _handles = []; + _methods = []; + } + + private static bool IsHandle(Type type) + { + if (!type.IsPointer) + return false; + + type = type.GetElementType(); + + if (type.FullName.StartsWith("System.")) + return false; + + // Our handle types don't need to be exported + // and these are all readonly structs. + // + // So skip these. + // + if (type.GetCustomAttribute() == null) + return false; + + return true; + } + + private bool TryAppendHandle(Type type) + { + if (!IsHandle(type)) + return false; + + if (_handles.ContainsKey(type.Name)) + return false; + + _handles.Add(type.Name, type); + + return true; + } + + public bool Append(MethodInfo method) + { + if (!method.IsStatic) + return false; + + var import = method.GetCustomAttribute(); + if (import == null) + return false; + + TryAppendHandle(method.ReturnType); + _enumWritter.TryAppend(method.ReturnType); + _structWritter.TryAppend(method.ReturnType); + + foreach (var arg in method.GetParameters()) + { + TryAppendHandle(arg.ParameterType); + _enumWritter.TryAppend(arg.ParameterType); + _structWritter.TryAppend(arg.ParameterType); + } + + _methods.Add(method); + return true; + } + + private void GenerateHandle(Type type) + { + type = type.GetElementType(); + _outputText.AppendLine($"struct {type.Name};"); + } + + private void GenerateMethod(MethodInfo method) + { + var import = method.GetCustomAttribute(); + + var rtype = Util.GetCTypeOrEnum(method.ReturnType); + var fname = import.EntryPoint ?? method.Name; + + var arguments = new List(); + foreach (var arg in method.GetParameters()) + { + var param = string.Format($"{Util.GetCTypeOrEnum(arg.ParameterType)} {arg.Name}"); + arguments.Add(param); + } + + _outputText.AppendLine($"MG_EXPORT {rtype} {fname}({string.Join(", ", arguments)});"); + } + + public void Flush(string dirPath) + { + // Write the handles. + foreach (var pair in _handles) + GenerateHandle(pair.Value); + + _outputText.AppendLine(); + + // Write the pinvokes. + foreach (var method in _methods) + GenerateMethod(method); + + var path = Path.Combine(dirPath, $"csharp_{_name}.h"); + File.WriteAllText(path, _outputText.ToString()); + } +} diff --git a/Tools/MonoGame.Generator.CTypes/Program.cs b/Tools/MonoGame.Generator.CTypes/Program.cs index 27c26f17050..7947832ff46 100644 --- a/Tools/MonoGame.Generator.CTypes/Program.cs +++ b/Tools/MonoGame.Generator.CTypes/Program.cs @@ -1,4 +1,8 @@ -using System.Reflection; +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System.Reflection; using MonoGame.Generator.CTypes; var repoDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../../../"); @@ -6,42 +10,27 @@ var monogameFrameworkPath = Path.Combine(repoDirectory, "Artifacts/MonoGame.Framework/Native/Debug/MonoGame.Framework.dll"); var assembly = Assembly.LoadFile(monogameFrameworkPath); var enumWritter = new EnumWritter(); -var structWrittter = new StructWritter(enumWritter); +var structWritter = new StructWritter(enumWritter); + +if (!Directory.Exists(monogamePlatformDir)) + Directory.CreateDirectory(monogamePlatformDir); foreach (var type in assembly.GetTypes()) -{ - if (type.FullName!.Contains("MonoGame.Interop")) - { - // Console.WriteLine(enumType.FullName!); - - - //Console.WriteLine(type.Name + ": " + StructWritter.IsValid(type)); - - if (!type.IsClass) - continue; - - foreach (var method in type.GetMethods()) - { - if (!method.IsStatic) - continue; - - Console.WriteLine(method.Name); - - foreach (var parm in method.GetParameters()) - { - Console.WriteLine(parm.ParameterType.Name + " " + parm.Name); - //Console.WriteLine(parm.ParameterType.Name + ": " + StructWritter.IsValid(parm.ParameterType)); - } - } - } - - if (EnumWritter.IsValid(type)) - { - enumWritter.Append(type); - } +{ + // Look for our interop types. + if (!type.FullName!.StartsWith("MonoGame.Interop.")) + continue; + + // All our interop pinvokes are static class methods. + if (!type.IsClass) + continue; + + var writter = new PinvokeWritter(type, structWritter, enumWritter); + foreach (var method in type.GetMethods()) + writter.Append(method); + + writter.Flush(monogamePlatformDir); } - -if (!Directory.Exists(monogamePlatformDir)) - Directory.CreateDirectory(monogamePlatformDir); - -enumWritter.Flush(Path.Combine(monogamePlatformDir)); + +enumWritter.Flush(monogamePlatformDir); +structWritter.Flush(monogamePlatformDir); diff --git a/Tools/MonoGame.Generator.CTypes/StructWritter.cs b/Tools/MonoGame.Generator.CTypes/StructWritter.cs index ea882369165..ffc103408d1 100644 --- a/Tools/MonoGame.Generator.CTypes/StructWritter.cs +++ b/Tools/MonoGame.Generator.CTypes/StructWritter.cs @@ -1,26 +1,110 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +using System; +using System.ComponentModel; +using System.Reflection; using System.Text; +using System.Runtime.CompilerServices; namespace MonoGame.Generator.CTypes; class StructWritter { - private EnumWritter _enumWritter; + private readonly Dictionary _types; + private readonly StringBuilder _outputText; + private readonly EnumWritter _enumWritter; public StructWritter(EnumWritter enumWritter) { _enumWritter = enumWritter; + + _outputText = new StringBuilder($""" + // + // This code is auto generated, don't modify it by hand. + // To regenerate it run: Tools/MonoGame.Generator.CTypes + // + + #pragma once + + #include "csharp_common.h" + + + """); + + _types = []; } - public static bool IsValid(Type type) + private static bool IsValid(Type type) { - return type.IsValueType && !type.IsPrimitive && !type.IsNested; + if (!type.IsValueType) + return false; + + if (type.IsEnum) + return false; + + if (type.IsNested) + return false; + + if (type.FullName.StartsWith("System.")) + return false; + + return true; } - public bool Append(Type type) + public bool TryAppend(Type type) { + if (type.IsPointer || type.IsByRef) + { + type = type.GetElementType(); + + // Our handle types don't need to be exported + // and these are all readonly structs. + // + // So skip these. + // + if (type.GetCustomAttribute() != null) + return false; + } + if (!IsValid(type)) return false; + if (_types.ContainsKey(type.Name)) + return true; + + _types.Add(type.Name, type); return true; } + + private void Generate(Type type) + { + _outputText.AppendLine($$""" + struct {{type.Name}} + { + public: + """); + + /* + foreach (var enumValue in enumValues) + { + _outputText.AppendLine($" case {enumValue}: return \"{enumValue}\";"); + } + */ + + _outputText.AppendLine(""" + }; + + """); + } + + public void Flush(string dirPath) + { + foreach (var pair in _types) + Generate(pair.Value); + + File.WriteAllText(Path.Combine(dirPath, "csharp_structs.h"), _outputText.ToString()); + } + } diff --git a/Tools/MonoGame.Generator.CTypes/Util.cs b/Tools/MonoGame.Generator.CTypes/Util.cs index c16662dbf04..7f91f41c5d7 100644 --- a/Tools/MonoGame.Generator.CTypes/Util.cs +++ b/Tools/MonoGame.Generator.CTypes/Util.cs @@ -1,17 +1,31 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. namespace MonoGame.Generator.CTypes; class Util { - public static string GetCEnumType(string cstype) => cstype switch + public static string GetCType(Type cstype) => cstype.ToString() switch { - "System.Byte" => "csbyte", - "System.Int16" => "csshort", - "System.UInt16" => "csushort", - "System.Int32" => "csint", - "System.UInt32" => "csuint", - "System.Int64" => "cslong", - "System.UInt64" => "csulong", - _ => "CS" + cstype + "System.Byte" => "mgbyte", + "System.Byte*" => "mgbyte*", + "System.Int16" => "mgshort", + "System.UInt16" => "mgushort", + "System.Int32" => "mgint", + "System.UInt32" => "mguint", + "System.Int64" => "mglong", + "System.UInt64" => "mgulong", + "System.Void" => "void", + "System.Boolean" => "mgbool", + _ => cstype.Name.ToString() }; + + public static string GetCTypeOrEnum(Type type) + { + if (type.IsEnum) + return $"MG{type.Name}"; + + return GetCType(type); + } } diff --git a/src/monogame/include/csharp_GameWrapper.h b/src/monogame/include/csharp_GameWrapper.h new file mode 100644 index 00000000000..625f5fdf773 --- /dev/null +++ b/src/monogame/include/csharp_GameWrapper.h @@ -0,0 +1,20 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +// +// This code is auto generated, don't modify it by hand. +// To regenerate it run: Tools/MonoGame.Generator.CTypes +// + +#pragma once + +#include "csharp_common.h" +#include "csharp_enums.h" +#include "csharp_structs.h" + + +struct Game; +struct GameWindow; + +MG_EXPORT void MG_GW_SetAllowUserResizing(Game* game, GameWindow* gameWindow, mgbool allowuserresizing); diff --git a/src/monogame/include/csharp_MGG.h b/src/monogame/include/csharp_MGG.h new file mode 100644 index 00000000000..53348e1d744 --- /dev/null +++ b/src/monogame/include/csharp_MGG.h @@ -0,0 +1,31 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +// +// This code is auto generated, don't modify it by hand. +// To regenerate it run: Tools/MonoGame.Generator.CTypes +// + +#pragma once + +#include "csharp_common.h" +#include "csharp_enums.h" +#include "csharp_structs.h" + + +struct MGG_GraphicsDevice; +struct MGG_Buffer; +struct MGG_Texture; + +MG_EXPORT MGG_GraphicsDevice* MGG_GraphicsDevice_Create(); +MG_EXPORT void MGG_GraphicsDevice_GetCaps(MGG_GraphicsDevice* device, MGG_GraphicsDevice_Caps& caps); +MG_EXPORT void MGG_GraphicsDevice_ResetBackbuffer(MGG_GraphicsDevice* device, mgint width, mgint height, MGSurfaceFormat color, MGDepthFormat depth); +MG_EXPORT mgint MGG_GraphicsDevice_BeginFrame(MGG_GraphicsDevice* device); +MG_EXPORT void MGG_GraphicsDevice_Present(MGG_GraphicsDevice* device, mgint currentFrame); +MG_EXPORT void MGG_GraphicsDevice_BindConstantBuffer(MGG_GraphicsDevice* device, MGShaderStage stage, mgint slot, MGG_Buffer* buffer); +MG_EXPORT MGG_Buffer* MGG_Buffer_Create(MGG_GraphicsDevice* device, mgint length); +MG_EXPORT void MGG_Buffer_SetData(MGG_GraphicsDevice* game, MGG_Buffer*& buffer, mgint offset, mgbyte* data, mgint length, mgbool discard); +MG_EXPORT void MGG_Buffer_Destroy(MGG_GraphicsDevice* device, MGG_Buffer* buffer); +MG_EXPORT MGG_Texture* MGG_Texture_Create(MGG_GraphicsDevice* device, MGSurfaceFormat format, mgint width, mgint height, mgint levels); +MG_EXPORT void MGG_Texture_Destroy(MGG_GraphicsDevice* device, MGG_Texture* texture); diff --git a/src/monogame/include/csharp_common.h b/src/monogame/include/csharp_common.h index 6d73cb6c663..351fe8ad23c 100644 --- a/src/monogame/include/csharp_common.h +++ b/src/monogame/include/csharp_common.h @@ -1,11 +1,22 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + #pragma once -typedef char cschar; -typedef unsigned char csbyte; -typedef short csshort; -typedef unsigned short csushort; -typedef int csint; -typedef unsigned int csuint; -typedef long long cslong; -typedef unsigned long long csulong; -typedef bool csbool; +typedef char mgchar; +typedef unsigned char mgbyte; +typedef short mgshort; +typedef unsigned short mgushort; +typedef int mgint; +typedef unsigned int mguint; +typedef long long mglong; +typedef unsigned long long mgulong; +typedef bool mgbool; + + +#ifdef DLL_EXPORT +#define MG_EXPORT extern "C" __declspec(dllexport) +#else +#define MG_EXPORT extern "C" +#endif diff --git a/src/monogame/include/csharp_enums.h b/src/monogame/include/csharp_enums.h index 2ed80ded63a..8905d6006df 100644 --- a/src/monogame/include/csharp_enums.h +++ b/src/monogame/include/csharp_enums.h @@ -7,1581 +7,7 @@ #include "csharp_common.h" -enum CSGraphicsBackend : csint -{ - DirectX = 0, - OpenGL = 1, - Vulkan = 2, - Metal = 3, -}; - -class ECSGraphicsBackend -{ -public: - static const char* ToString(CSGraphicsBackend enumValue) - { - switch (enumValue) - { - case DirectX: return "DirectX"; - case OpenGL: return "OpenGL"; - case Vulkan: return "Vulkan"; - case Metal: return "Metal"; - } - - return "Unknown Value"; - } -}; - -enum CSMonoGamePlatform : csint -{ - Android = 0, - iOS = 1, - tvOS = 2, - DesktopGL = 3, - Windows = 4, - WindowsUniversal = 5, - WebGL = 6, - XboxOne = 7, - PlayStation4 = 8, - PlayStation5 = 9, - NintendoSwitch = 10, - Stadia = 11, -}; - -class ECSMonoGamePlatform -{ -public: - static const char* ToString(CSMonoGamePlatform enumValue) - { - switch (enumValue) - { - case Android: return "Android"; - case iOS: return "iOS"; - case tvOS: return "tvOS"; - case DesktopGL: return "DesktopGL"; - case Windows: return "Windows"; - case WindowsUniversal: return "WindowsUniversal"; - case WebGL: return "WebGL"; - case XboxOne: return "XboxOne"; - case PlayStation4: return "PlayStation4"; - case PlayStation5: return "PlayStation5"; - case NintendoSwitch: return "NintendoSwitch"; - case Stadia: return "Stadia"; - } - - return "Unknown Value"; - } -}; - -enum CSContainmentType : csint -{ - Disjoint = 0, - Contains = 1, - Intersects = 2, -}; - -class ECSContainmentType -{ -public: - static const char* ToString(CSContainmentType enumValue) - { - switch (enumValue) - { - case Disjoint: return "Disjoint"; - case Contains: return "Contains"; - case Intersects: return "Intersects"; - } - - return "Unknown Value"; - } -}; - -enum CSCurveContinuity : csint -{ - Smooth = 0, - Step = 1, -}; - -class ECSCurveContinuity -{ -public: - static const char* ToString(CSCurveContinuity enumValue) - { - switch (enumValue) - { - case Smooth: return "Smooth"; - case Step: return "Step"; - } - - return "Unknown Value"; - } -}; - -enum CSCurveLoopType : csint -{ - Constant = 0, - Cycle = 1, - CycleOffset = 2, - Oscillate = 3, - Linear = 4, -}; - -class ECSCurveLoopType -{ -public: - static const char* ToString(CSCurveLoopType enumValue) - { - switch (enumValue) - { - case Constant: return "Constant"; - case Cycle: return "Cycle"; - case CycleOffset: return "CycleOffset"; - case Oscillate: return "Oscillate"; - case Linear: return "Linear"; - } - - return "Unknown Value"; - } -}; - -enum CSCurveTangent : csint -{ - Flat = 0, - Linear = 1, - Smooth = 2, -}; - -class ECSCurveTangent -{ -public: - static const char* ToString(CSCurveTangent enumValue) - { - switch (enumValue) - { - case Flat: return "Flat"; - case Linear: return "Linear"; - case Smooth: return "Smooth"; - } - - return "Unknown Value"; - } -}; - -enum CSDisplayOrientation : csint -{ - Default = 0, - LandscapeLeft = 1, - LandscapeRight = 2, - Portrait = 4, - PortraitDown = 8, - Unknown = 16, -}; - -class ECSDisplayOrientation -{ -public: - static const char* ToString(CSDisplayOrientation enumValue) - { - switch (enumValue) - { - case Default: return "Default"; - case LandscapeLeft: return "LandscapeLeft"; - case LandscapeRight: return "LandscapeRight"; - case Portrait: return "Portrait"; - case PortraitDown: return "PortraitDown"; - case Unknown: return "Unknown"; - } - - return "Unknown Value"; - } -}; - -enum CSGameRunBehavior : csint -{ - Asynchronous = 0, - Synchronous = 1, -}; - -class ECSGameRunBehavior -{ -public: - static const char* ToString(CSGameRunBehavior enumValue) - { - switch (enumValue) - { - case Asynchronous: return "Asynchronous"; - case Synchronous: return "Synchronous"; - } - - return "Unknown Value"; - } -}; - -enum CSPlaneIntersectionType : csint -{ - Front = 0, - Back = 1, - Intersecting = 2, -}; - -class ECSPlaneIntersectionType -{ -public: - static const char* ToString(CSPlaneIntersectionType enumValue) - { - switch (enumValue) - { - case Front: return "Front"; - case Back: return "Back"; - case Intersecting: return "Intersecting"; - } - - return "Unknown Value"; - } -}; - -enum CSPlayerIndex : csint -{ - One = 0, - Two = 1, - Three = 2, - Four = 3, -}; - -class ECSPlayerIndex -{ -public: - static const char* ToString(CSPlayerIndex enumValue) - { - switch (enumValue) - { - case One: return "One"; - case Two: return "Two"; - case Three: return "Three"; - case Four: return "Four"; - } - - return "Unknown Value"; - } -}; - -enum CSMediaSourceType : csint -{ - LocalDevice = 0, - WindowsMediaConnect = 4, -}; - -class ECSMediaSourceType -{ -public: - static const char* ToString(CSMediaSourceType enumValue) - { - switch (enumValue) - { - case LocalDevice: return "LocalDevice"; - case WindowsMediaConnect: return "WindowsMediaConnect"; - } - - return "Unknown Value"; - } -}; - -enum CSMediaState : csint -{ - Stopped = 0, - Playing = 1, - Paused = 2, -}; - -class ECSMediaState -{ -public: - static const char* ToString(CSMediaState enumValue) - { - switch (enumValue) - { - case Stopped: return "Stopped"; - case Playing: return "Playing"; - case Paused: return "Paused"; - } - - return "Unknown Value"; - } -}; - -enum CSVideoSoundtrackType : csint -{ - Music = 0, - Dialog = 1, - MusicAndDialog = 2, -}; - -class ECSVideoSoundtrackType -{ -public: - static const char* ToString(CSVideoSoundtrackType enumValue) - { - switch (enumValue) - { - case Music: return "Music"; - case Dialog: return "Dialog"; - case MusicAndDialog: return "MusicAndDialog"; - } - - return "Unknown Value"; - } -}; - -enum CSButtons : csint -{ - None = 0, - DPadUp = 1, - DPadDown = 2, - DPadLeft = 4, - DPadRight = 8, - Start = 16, - Back = 32, - LeftStick = 64, - RightStick = 128, - LeftShoulder = 256, - RightShoulder = 512, - BigButton = 2048, - A = 4096, - B = 8192, - X = 16384, - Y = 32768, - LeftThumbstickLeft = 2097152, - RightTrigger = 4194304, - LeftTrigger = 8388608, - RightThumbstickUp = 16777216, - RightThumbstickDown = 33554432, - RightThumbstickRight = 67108864, - RightThumbstickLeft = 134217728, - LeftThumbstickUp = 268435456, - LeftThumbstickDown = 536870912, - LeftThumbstickRight = 1073741824, -}; - -class ECSButtons -{ -public: - static const char* ToString(CSButtons enumValue) - { - switch (enumValue) - { - case None: return "None"; - case DPadUp: return "DPadUp"; - case DPadDown: return "DPadDown"; - case DPadLeft: return "DPadLeft"; - case DPadRight: return "DPadRight"; - case Start: return "Start"; - case Back: return "Back"; - case LeftStick: return "LeftStick"; - case RightStick: return "RightStick"; - case LeftShoulder: return "LeftShoulder"; - case RightShoulder: return "RightShoulder"; - case BigButton: return "BigButton"; - case A: return "A"; - case B: return "B"; - case X: return "X"; - case Y: return "Y"; - case LeftThumbstickLeft: return "LeftThumbstickLeft"; - case RightTrigger: return "RightTrigger"; - case LeftTrigger: return "LeftTrigger"; - case RightThumbstickUp: return "RightThumbstickUp"; - case RightThumbstickDown: return "RightThumbstickDown"; - case RightThumbstickRight: return "RightThumbstickRight"; - case RightThumbstickLeft: return "RightThumbstickLeft"; - case LeftThumbstickUp: return "LeftThumbstickUp"; - case LeftThumbstickDown: return "LeftThumbstickDown"; - case LeftThumbstickRight: return "LeftThumbstickRight"; - } - - return "Unknown Value"; - } -}; - -enum CSButtonState : csint -{ - Released = 0, - Pressed = 1, -}; - -class ECSButtonState -{ -public: - static const char* ToString(CSButtonState enumValue) - { - switch (enumValue) - { - case Released: return "Released"; - case Pressed: return "Pressed"; - } - - return "Unknown Value"; - } -}; - -enum CSGamePadDeadZone : csint -{ - None = 0, - IndependentAxes = 1, - Circular = 2, -}; - -class ECSGamePadDeadZone -{ -public: - static const char* ToString(CSGamePadDeadZone enumValue) - { - switch (enumValue) - { - case None: return "None"; - case IndependentAxes: return "IndependentAxes"; - case Circular: return "Circular"; - } - - return "Unknown Value"; - } -}; - -enum CSGamePadType : csint -{ - Unknown = 0, - GamePad = 1, - Wheel = 2, - ArcadeStick = 3, - FlightStick = 4, - DancePad = 5, - Guitar = 6, - AlternateGuitar = 7, - DrumKit = 8, - BigButtonPad = 768, -}; - -class ECSGamePadType -{ -public: - static const char* ToString(CSGamePadType enumValue) - { - switch (enumValue) - { - case Unknown: return "Unknown"; - case GamePad: return "GamePad"; - case Wheel: return "Wheel"; - case ArcadeStick: return "ArcadeStick"; - case FlightStick: return "FlightStick"; - case DancePad: return "DancePad"; - case Guitar: return "Guitar"; - case AlternateGuitar: return "AlternateGuitar"; - case DrumKit: return "DrumKit"; - case BigButtonPad: return "BigButtonPad"; - } - - return "Unknown Value"; - } -}; - -enum CSKeys : csint -{ - None = 0, - Back = 8, - Tab = 9, - Enter = 13, - Pause = 19, - CapsLock = 20, - Kana = 21, - Kanji = 25, - Escape = 27, - ImeConvert = 28, - ImeNoConvert = 29, - Space = 32, - PageUp = 33, - PageDown = 34, - End = 35, - Home = 36, - Left = 37, - Up = 38, - Right = 39, - Down = 40, - Select = 41, - Print = 42, - Execute = 43, - PrintScreen = 44, - Insert = 45, - Delete = 46, - Help = 47, - D0 = 48, - D1 = 49, - D2 = 50, - D3 = 51, - D4 = 52, - D5 = 53, - D6 = 54, - D7 = 55, - D8 = 56, - D9 = 57, - A = 65, - B = 66, - C = 67, - D = 68, - E = 69, - F = 70, - G = 71, - H = 72, - I = 73, - J = 74, - K = 75, - L = 76, - M = 77, - N = 78, - O = 79, - P = 80, - Q = 81, - R = 82, - S = 83, - T = 84, - U = 85, - V = 86, - W = 87, - X = 88, - Y = 89, - Z = 90, - LeftWindows = 91, - RightWindows = 92, - Apps = 93, - Sleep = 95, - NumPad0 = 96, - NumPad1 = 97, - NumPad2 = 98, - NumPad3 = 99, - NumPad4 = 100, - NumPad5 = 101, - NumPad6 = 102, - NumPad7 = 103, - NumPad8 = 104, - NumPad9 = 105, - Multiply = 106, - Add = 107, - Separator = 108, - Subtract = 109, - Decimal = 110, - Divide = 111, - F1 = 112, - F2 = 113, - F3 = 114, - F4 = 115, - F5 = 116, - F6 = 117, - F7 = 118, - F8 = 119, - F9 = 120, - F10 = 121, - F11 = 122, - F12 = 123, - F13 = 124, - F14 = 125, - F15 = 126, - F16 = 127, - F17 = 128, - F18 = 129, - F19 = 130, - F20 = 131, - F21 = 132, - F22 = 133, - F23 = 134, - F24 = 135, - NumLock = 144, - Scroll = 145, - LeftShift = 160, - RightShift = 161, - LeftControl = 162, - RightControl = 163, - LeftAlt = 164, - RightAlt = 165, - BrowserBack = 166, - BrowserForward = 167, - BrowserRefresh = 168, - BrowserStop = 169, - BrowserSearch = 170, - BrowserFavorites = 171, - BrowserHome = 172, - VolumeMute = 173, - VolumeDown = 174, - VolumeUp = 175, - MediaNextTrack = 176, - MediaPreviousTrack = 177, - MediaStop = 178, - MediaPlayPause = 179, - LaunchMail = 180, - SelectMedia = 181, - LaunchApplication1 = 182, - LaunchApplication2 = 183, - OemSemicolon = 186, - OemPlus = 187, - OemComma = 188, - OemMinus = 189, - OemPeriod = 190, - OemQuestion = 191, - OemTilde = 192, - ChatPadGreen = 202, - ChatPadOrange = 203, - OemOpenBrackets = 219, - OemPipe = 220, - OemCloseBrackets = 221, - OemQuotes = 222, - Oem8 = 223, - OemBackslash = 226, - ProcessKey = 229, - OemCopy = 242, - OemAuto = 243, - OemEnlW = 244, - Attn = 246, - Crsel = 247, - Exsel = 248, - EraseEof = 249, - Play = 250, - Zoom = 251, - Pa1 = 253, - OemClear = 254, -}; - -class ECSKeys -{ -public: - static const char* ToString(CSKeys enumValue) - { - switch (enumValue) - { - case None: return "None"; - case Back: return "Back"; - case Tab: return "Tab"; - case Enter: return "Enter"; - case Pause: return "Pause"; - case CapsLock: return "CapsLock"; - case Kana: return "Kana"; - case Kanji: return "Kanji"; - case Escape: return "Escape"; - case ImeConvert: return "ImeConvert"; - case ImeNoConvert: return "ImeNoConvert"; - case Space: return "Space"; - case PageUp: return "PageUp"; - case PageDown: return "PageDown"; - case End: return "End"; - case Home: return "Home"; - case Left: return "Left"; - case Up: return "Up"; - case Right: return "Right"; - case Down: return "Down"; - case Select: return "Select"; - case Print: return "Print"; - case Execute: return "Execute"; - case PrintScreen: return "PrintScreen"; - case Insert: return "Insert"; - case Delete: return "Delete"; - case Help: return "Help"; - case D0: return "D0"; - case D1: return "D1"; - case D2: return "D2"; - case D3: return "D3"; - case D4: return "D4"; - case D5: return "D5"; - case D6: return "D6"; - case D7: return "D7"; - case D8: return "D8"; - case D9: return "D9"; - case A: return "A"; - case B: return "B"; - case C: return "C"; - case D: return "D"; - case E: return "E"; - case F: return "F"; - case G: return "G"; - case H: return "H"; - case I: return "I"; - case J: return "J"; - case K: return "K"; - case L: return "L"; - case M: return "M"; - case N: return "N"; - case O: return "O"; - case P: return "P"; - case Q: return "Q"; - case R: return "R"; - case S: return "S"; - case T: return "T"; - case U: return "U"; - case V: return "V"; - case W: return "W"; - case X: return "X"; - case Y: return "Y"; - case Z: return "Z"; - case LeftWindows: return "LeftWindows"; - case RightWindows: return "RightWindows"; - case Apps: return "Apps"; - case Sleep: return "Sleep"; - case NumPad0: return "NumPad0"; - case NumPad1: return "NumPad1"; - case NumPad2: return "NumPad2"; - case NumPad3: return "NumPad3"; - case NumPad4: return "NumPad4"; - case NumPad5: return "NumPad5"; - case NumPad6: return "NumPad6"; - case NumPad7: return "NumPad7"; - case NumPad8: return "NumPad8"; - case NumPad9: return "NumPad9"; - case Multiply: return "Multiply"; - case Add: return "Add"; - case Separator: return "Separator"; - case Subtract: return "Subtract"; - case Decimal: return "Decimal"; - case Divide: return "Divide"; - case F1: return "F1"; - case F2: return "F2"; - case F3: return "F3"; - case F4: return "F4"; - case F5: return "F5"; - case F6: return "F6"; - case F7: return "F7"; - case F8: return "F8"; - case F9: return "F9"; - case F10: return "F10"; - case F11: return "F11"; - case F12: return "F12"; - case F13: return "F13"; - case F14: return "F14"; - case F15: return "F15"; - case F16: return "F16"; - case F17: return "F17"; - case F18: return "F18"; - case F19: return "F19"; - case F20: return "F20"; - case F21: return "F21"; - case F22: return "F22"; - case F23: return "F23"; - case F24: return "F24"; - case NumLock: return "NumLock"; - case Scroll: return "Scroll"; - case LeftShift: return "LeftShift"; - case RightShift: return "RightShift"; - case LeftControl: return "LeftControl"; - case RightControl: return "RightControl"; - case LeftAlt: return "LeftAlt"; - case RightAlt: return "RightAlt"; - case BrowserBack: return "BrowserBack"; - case BrowserForward: return "BrowserForward"; - case BrowserRefresh: return "BrowserRefresh"; - case BrowserStop: return "BrowserStop"; - case BrowserSearch: return "BrowserSearch"; - case BrowserFavorites: return "BrowserFavorites"; - case BrowserHome: return "BrowserHome"; - case VolumeMute: return "VolumeMute"; - case VolumeDown: return "VolumeDown"; - case VolumeUp: return "VolumeUp"; - case MediaNextTrack: return "MediaNextTrack"; - case MediaPreviousTrack: return "MediaPreviousTrack"; - case MediaStop: return "MediaStop"; - case MediaPlayPause: return "MediaPlayPause"; - case LaunchMail: return "LaunchMail"; - case SelectMedia: return "SelectMedia"; - case LaunchApplication1: return "LaunchApplication1"; - case LaunchApplication2: return "LaunchApplication2"; - case OemSemicolon: return "OemSemicolon"; - case OemPlus: return "OemPlus"; - case OemComma: return "OemComma"; - case OemMinus: return "OemMinus"; - case OemPeriod: return "OemPeriod"; - case OemQuestion: return "OemQuestion"; - case OemTilde: return "OemTilde"; - case ChatPadGreen: return "ChatPadGreen"; - case ChatPadOrange: return "ChatPadOrange"; - case OemOpenBrackets: return "OemOpenBrackets"; - case OemPipe: return "OemPipe"; - case OemCloseBrackets: return "OemCloseBrackets"; - case OemQuotes: return "OemQuotes"; - case Oem8: return "Oem8"; - case OemBackslash: return "OemBackslash"; - case ProcessKey: return "ProcessKey"; - case OemCopy: return "OemCopy"; - case OemAuto: return "OemAuto"; - case OemEnlW: return "OemEnlW"; - case Attn: return "Attn"; - case Crsel: return "Crsel"; - case Exsel: return "Exsel"; - case EraseEof: return "EraseEof"; - case Play: return "Play"; - case Zoom: return "Zoom"; - case Pa1: return "Pa1"; - case OemClear: return "OemClear"; - } - - return "Unknown Value"; - } -}; - -enum CSKeyState : csint -{ - Up = 0, - Down = 1, -}; - -class ECSKeyState -{ -public: - static const char* ToString(CSKeyState enumValue) - { - switch (enumValue) - { - case Up: return "Up"; - case Down: return "Down"; - } - - return "Unknown Value"; - } -}; - -enum CSGestureType : csint -{ - None = 0, - Tap = 1, - DragComplete = 2, - Flick = 4, - FreeDrag = 8, - Hold = 16, - HorizontalDrag = 32, - Pinch = 64, - PinchComplete = 128, - DoubleTap = 256, - VerticalDrag = 512, -}; - -class ECSGestureType -{ -public: - static const char* ToString(CSGestureType enumValue) - { - switch (enumValue) - { - case None: return "None"; - case Tap: return "Tap"; - case DragComplete: return "DragComplete"; - case Flick: return "Flick"; - case FreeDrag: return "FreeDrag"; - case Hold: return "Hold"; - case HorizontalDrag: return "HorizontalDrag"; - case Pinch: return "Pinch"; - case PinchComplete: return "PinchComplete"; - case DoubleTap: return "DoubleTap"; - case VerticalDrag: return "VerticalDrag"; - } - - return "Unknown Value"; - } -}; - -enum CSTouchLocationState : csint -{ - Invalid = 0, - Moved = 1, - Pressed = 2, - Released = 3, -}; - -class ECSTouchLocationState -{ -public: - static const char* ToString(CSTouchLocationState enumValue) - { - switch (enumValue) - { - case Invalid: return "Invalid"; - case Moved: return "Moved"; - case Pressed: return "Pressed"; - case Released: return "Released"; - } - - return "Unknown Value"; - } -}; - -enum CSClearOptions : csint -{ - Target = 1, - DepthBuffer = 2, - Stencil = 4, -}; - -class ECSClearOptions -{ -public: - static const char* ToString(CSClearOptions enumValue) - { - switch (enumValue) - { - case Target: return "Target"; - case DepthBuffer: return "DepthBuffer"; - case Stencil: return "Stencil"; - } - - return "Unknown Value"; - } -}; - -enum CSColorWriteChannels : csint -{ - None = 0, - Red = 1, - Green = 2, - Blue = 4, - Alpha = 8, - All = 15, -}; - -class ECSColorWriteChannels -{ -public: - static const char* ToString(CSColorWriteChannels enumValue) - { - switch (enumValue) - { - case None: return "None"; - case Red: return "Red"; - case Green: return "Green"; - case Blue: return "Blue"; - case Alpha: return "Alpha"; - case All: return "All"; - } - - return "Unknown Value"; - } -}; - -enum CSCubeMapFace : csint -{ - PositiveX = 0, - NegativeX = 1, - PositiveY = 2, - NegativeY = 3, - PositiveZ = 4, - NegativeZ = 5, -}; - -class ECSCubeMapFace -{ -public: - static const char* ToString(CSCubeMapFace enumValue) - { - switch (enumValue) - { - case PositiveX: return "PositiveX"; - case NegativeX: return "NegativeX"; - case PositiveY: return "PositiveY"; - case NegativeY: return "NegativeY"; - case PositiveZ: return "PositiveZ"; - case NegativeZ: return "NegativeZ"; - } - - return "Unknown Value"; - } -}; - -enum CSEffectDirtyFlags : csint -{ - WorldViewProj = 1, - World = 2, - EyePosition = 4, - MaterialColor = 8, - Fog = 16, - FogEnable = 32, - AlphaTest = 64, - ShaderIndex = 128, - All = -1, -}; - -class ECSEffectDirtyFlags -{ -public: - static const char* ToString(CSEffectDirtyFlags enumValue) - { - switch (enumValue) - { - case WorldViewProj: return "WorldViewProj"; - case World: return "World"; - case EyePosition: return "EyePosition"; - case MaterialColor: return "MaterialColor"; - case Fog: return "Fog"; - case FogEnable: return "FogEnable"; - case AlphaTest: return "AlphaTest"; - case ShaderIndex: return "ShaderIndex"; - case All: return "All"; - } - - return "Unknown Value"; - } -}; - -enum CSEffectParameterClass : csint -{ - Scalar = 0, - Vector = 1, - Matrix = 2, - Object = 3, - Struct = 4, -}; - -class ECSEffectParameterClass -{ -public: - static const char* ToString(CSEffectParameterClass enumValue) - { - switch (enumValue) - { - case Scalar: return "Scalar"; - case Vector: return "Vector"; - case Matrix: return "Matrix"; - case Object: return "Object"; - case Struct: return "Struct"; - } - - return "Unknown Value"; - } -}; - -enum CSEffectParameterType : csint -{ - Void = 0, - Bool = 1, - Int32 = 2, - Single = 3, - String = 4, - Texture = 5, - Texture1D = 6, - Texture2D = 7, - Texture3D = 8, - TextureCube = 9, -}; - -class ECSEffectParameterType -{ -public: - static const char* ToString(CSEffectParameterType enumValue) - { - switch (enumValue) - { - case Void: return "Void"; - case Bool: return "Bool"; - case Int32: return "Int32"; - case Single: return "Single"; - case String: return "String"; - case Texture: return "Texture"; - case Texture1D: return "Texture1D"; - case Texture2D: return "Texture2D"; - case Texture3D: return "Texture3D"; - case TextureCube: return "TextureCube"; - } - - return "Unknown Value"; - } -}; - -enum CSGraphicsDeviceStatus : csint -{ - Normal = 0, - Lost = 1, - NotReset = 2, -}; - -class ECSGraphicsDeviceStatus -{ -public: - static const char* ToString(CSGraphicsDeviceStatus enumValue) - { - switch (enumValue) - { - case Normal: return "Normal"; - case Lost: return "Lost"; - case NotReset: return "NotReset"; - } - - return "Unknown Value"; - } -}; - -enum CSGraphicsProfile : csint -{ - Reach = 0, - HiDef = 1, -}; - -class ECSGraphicsProfile -{ -public: - static const char* ToString(CSGraphicsProfile enumValue) - { - switch (enumValue) - { - case Reach: return "Reach"; - case HiDef: return "HiDef"; - } - - return "Unknown Value"; - } -}; - -enum CSPresentInterval : csint -{ - Default = 0, - One = 1, - Two = 2, - Immediate = 3, -}; - -class ECSPresentInterval -{ -public: - static const char* ToString(CSPresentInterval enumValue) - { - switch (enumValue) - { - case Default: return "Default"; - case One: return "One"; - case Two: return "Two"; - case Immediate: return "Immediate"; - } - - return "Unknown Value"; - } -}; - -enum CSRenderTargetUsage : csint -{ - DiscardContents = 0, - PreserveContents = 1, - PlatformContents = 2, -}; - -class ECSRenderTargetUsage -{ -public: - static const char* ToString(CSRenderTargetUsage enumValue) - { - switch (enumValue) - { - case DiscardContents: return "DiscardContents"; - case PreserveContents: return "PreserveContents"; - case PlatformContents: return "PlatformContents"; - } - - return "Unknown Value"; - } -}; - -enum CSSetDataOptions : csint -{ - None = 0, - Discard = 1, - NoOverwrite = 2, -}; - -class ECSSetDataOptions -{ -public: - static const char* ToString(CSSetDataOptions enumValue) - { - switch (enumValue) - { - case None: return "None"; - case Discard: return "Discard"; - case NoOverwrite: return "NoOverwrite"; - } - - return "Unknown Value"; - } -}; - -enum CSSamplerType : csint -{ - Sampler2D = 0, - SamplerCube = 1, - SamplerVolume = 2, - Sampler1D = 3, -}; - -class ECSSamplerType -{ -public: - static const char* ToString(CSSamplerType enumValue) - { - switch (enumValue) - { - case Sampler2D: return "Sampler2D"; - case SamplerCube: return "SamplerCube"; - case SamplerVolume: return "SamplerVolume"; - case Sampler1D: return "Sampler1D"; - } - - return "Unknown Value"; - } -}; - -enum CSShaderStage : csint -{ - Vertex = 0, - Pixel = 1, -}; - -class ECSShaderStage -{ -public: - static const char* ToString(CSShaderStage enumValue) - { - switch (enumValue) - { - case Vertex: return "Vertex"; - case Pixel: return "Pixel"; - } - - return "Unknown Value"; - } -}; - -enum CSSpriteEffects : csint -{ - None = 0, - FlipHorizontally = 1, - FlipVertically = 2, -}; - -class ECSSpriteEffects -{ -public: - static const char* ToString(CSSpriteEffects enumValue) - { - switch (enumValue) - { - case None: return "None"; - case FlipHorizontally: return "FlipHorizontally"; - case FlipVertically: return "FlipVertically"; - } - - return "Unknown Value"; - } -}; - -enum CSSpriteSortMode : csint -{ - Deferred = 0, - Immediate = 1, - Texture = 2, - BackToFront = 3, - FrontToBack = 4, -}; - -class ECSSpriteSortMode -{ -public: - static const char* ToString(CSSpriteSortMode enumValue) - { - switch (enumValue) - { - case Deferred: return "Deferred"; - case Immediate: return "Immediate"; - case Texture: return "Texture"; - case BackToFront: return "BackToFront"; - case FrontToBack: return "FrontToBack"; - } - - return "Unknown Value"; - } -}; - -enum CSBlend : csint -{ - One = 0, - Zero = 1, - SourceColor = 2, - InverseSourceColor = 3, - SourceAlpha = 4, - InverseSourceAlpha = 5, - DestinationColor = 6, - InverseDestinationColor = 7, - DestinationAlpha = 8, - InverseDestinationAlpha = 9, - BlendFactor = 10, - InverseBlendFactor = 11, - SourceAlphaSaturation = 12, -}; - -class ECSBlend -{ -public: - static const char* ToString(CSBlend enumValue) - { - switch (enumValue) - { - case One: return "One"; - case Zero: return "Zero"; - case SourceColor: return "SourceColor"; - case InverseSourceColor: return "InverseSourceColor"; - case SourceAlpha: return "SourceAlpha"; - case InverseSourceAlpha: return "InverseSourceAlpha"; - case DestinationColor: return "DestinationColor"; - case InverseDestinationColor: return "InverseDestinationColor"; - case DestinationAlpha: return "DestinationAlpha"; - case InverseDestinationAlpha: return "InverseDestinationAlpha"; - case BlendFactor: return "BlendFactor"; - case InverseBlendFactor: return "InverseBlendFactor"; - case SourceAlphaSaturation: return "SourceAlphaSaturation"; - } - - return "Unknown Value"; - } -}; - -enum CSBlendFunction : csint -{ - Add = 0, - Subtract = 1, - ReverseSubtract = 2, - Min = 3, - Max = 4, -}; - -class ECSBlendFunction -{ -public: - static const char* ToString(CSBlendFunction enumValue) - { - switch (enumValue) - { - case Add: return "Add"; - case Subtract: return "Subtract"; - case ReverseSubtract: return "ReverseSubtract"; - case Min: return "Min"; - case Max: return "Max"; - } - - return "Unknown Value"; - } -}; - -enum CSCompareFunction : csint -{ - Always = 0, - Never = 1, - Less = 2, - LessEqual = 3, - Equal = 4, - GreaterEqual = 5, - Greater = 6, - NotEqual = 7, -}; - -class ECSCompareFunction -{ -public: - static const char* ToString(CSCompareFunction enumValue) - { - switch (enumValue) - { - case Always: return "Always"; - case Never: return "Never"; - case Less: return "Less"; - case LessEqual: return "LessEqual"; - case Equal: return "Equal"; - case GreaterEqual: return "GreaterEqual"; - case Greater: return "Greater"; - case NotEqual: return "NotEqual"; - } - - return "Unknown Value"; - } -}; - -enum CSCullMode : csint -{ - None = 0, - CullClockwiseFace = 1, - CullCounterClockwiseFace = 2, -}; - -class ECSCullMode -{ -public: - static const char* ToString(CSCullMode enumValue) - { - switch (enumValue) - { - case None: return "None"; - case CullClockwiseFace: return "CullClockwiseFace"; - case CullCounterClockwiseFace: return "CullCounterClockwiseFace"; - } - - return "Unknown Value"; - } -}; - -enum CSDepthFormat : csint -{ - None = 0, - Depth16 = 1, - Depth24 = 2, - Depth24Stencil8 = 3, -}; - -class ECSDepthFormat -{ -public: - static const char* ToString(CSDepthFormat enumValue) - { - switch (enumValue) - { - case None: return "None"; - case Depth16: return "Depth16"; - case Depth24: return "Depth24"; - case Depth24Stencil8: return "Depth24Stencil8"; - } - - return "Unknown Value"; - } -}; - -enum CSFillMode : csint -{ - Solid = 0, - WireFrame = 1, -}; - -class ECSFillMode -{ -public: - static const char* ToString(CSFillMode enumValue) - { - switch (enumValue) - { - case Solid: return "Solid"; - case WireFrame: return "WireFrame"; - } - - return "Unknown Value"; - } -}; - -enum CSStencilOperation : csint -{ - Keep = 0, - Zero = 1, - Replace = 2, - Increment = 3, - Decrement = 4, - IncrementSaturation = 5, - DecrementSaturation = 6, - Invert = 7, -}; - -class ECSStencilOperation -{ -public: - static const char* ToString(CSStencilOperation enumValue) - { - switch (enumValue) - { - case Keep: return "Keep"; - case Zero: return "Zero"; - case Replace: return "Replace"; - case Increment: return "Increment"; - case Decrement: return "Decrement"; - case IncrementSaturation: return "IncrementSaturation"; - case DecrementSaturation: return "DecrementSaturation"; - case Invert: return "Invert"; - } - - return "Unknown Value"; - } -}; - -enum CSTextureAddressMode : csint -{ - Wrap = 0, - Clamp = 1, - Mirror = 2, - Border = 3, -}; - -class ECSTextureAddressMode -{ -public: - static const char* ToString(CSTextureAddressMode enumValue) - { - switch (enumValue) - { - case Wrap: return "Wrap"; - case Clamp: return "Clamp"; - case Mirror: return "Mirror"; - case Border: return "Border"; - } - - return "Unknown Value"; - } -}; - -enum CSTextureFilter : csint -{ - Linear = 0, - Point = 1, - Anisotropic = 2, - LinearMipPoint = 3, - PointMipLinear = 4, - MinLinearMagPointMipLinear = 5, - MinLinearMagPointMipPoint = 6, - MinPointMagLinearMipLinear = 7, - MinPointMagLinearMipPoint = 8, -}; - -class ECSTextureFilter -{ -public: - static const char* ToString(CSTextureFilter enumValue) - { - switch (enumValue) - { - case Linear: return "Linear"; - case Point: return "Point"; - case Anisotropic: return "Anisotropic"; - case LinearMipPoint: return "LinearMipPoint"; - case PointMipLinear: return "PointMipLinear"; - case MinLinearMagPointMipLinear: return "MinLinearMagPointMipLinear"; - case MinLinearMagPointMipPoint: return "MinLinearMagPointMipPoint"; - case MinPointMagLinearMipLinear: return "MinPointMagLinearMipLinear"; - case MinPointMagLinearMipPoint: return "MinPointMagLinearMipPoint"; - } - - return "Unknown Value"; - } -}; - -enum CSTextureFilterMode : csint -{ - Default = 0, - Comparison = 1, -}; - -class ECSTextureFilterMode -{ -public: - static const char* ToString(CSTextureFilterMode enumValue) - { - switch (enumValue) - { - case Default: return "Default"; - case Comparison: return "Comparison"; - } - - return "Unknown Value"; - } -}; - -enum CSSurfaceFormat : csint +enum MGSurfaceFormat : mgint { Color = 0, Bgr565 = 1, @@ -1627,10 +53,10 @@ enum CSSurfaceFormat : csint SRgb8A8Etc2 = 95, }; -class ECSSurfaceFormat +class EMGSurfaceFormat { public: - static const char* ToString(CSSurfaceFormat enumValue) + static const char* ToString(MGSurfaceFormat enumValue) { switch (enumValue) { @@ -1682,420 +108,46 @@ class ECSSurfaceFormat } }; -enum CSBufferUsage : csint +enum MGDepthFormat : mgint { None = 0, - WriteOnly = 1, + Depth16 = 1, + Depth24 = 2, + Depth24Stencil8 = 3, }; -class ECSBufferUsage +class EMGDepthFormat { public: - static const char* ToString(CSBufferUsage enumValue) + static const char* ToString(MGDepthFormat enumValue) { switch (enumValue) { case None: return "None"; - case WriteOnly: return "WriteOnly"; - } - - return "Unknown Value"; - } -}; - -enum CSIndexElementSize : csint -{ - SixteenBits = 0, - ThirtyTwoBits = 1, -}; - -class ECSIndexElementSize -{ -public: - static const char* ToString(CSIndexElementSize enumValue) - { - switch (enumValue) - { - case SixteenBits: return "SixteenBits"; - case ThirtyTwoBits: return "ThirtyTwoBits"; - } - - return "Unknown Value"; - } -}; - -enum CSPrimitiveType : csint -{ - TriangleList = 0, - TriangleStrip = 1, - LineList = 2, - LineStrip = 3, - PointList = 4, -}; - -class ECSPrimitiveType -{ -public: - static const char* ToString(CSPrimitiveType enumValue) - { - switch (enumValue) - { - case TriangleList: return "TriangleList"; - case TriangleStrip: return "TriangleStrip"; - case LineList: return "LineList"; - case LineStrip: return "LineStrip"; - case PointList: return "PointList"; - } - - return "Unknown Value"; - } -}; - -enum CSVertexElementFormat : csint -{ - Single = 0, - Vector2 = 1, - Vector3 = 2, - Vector4 = 3, - Color = 4, - Byte4 = 5, - Short2 = 6, - Short4 = 7, - NormalizedShort2 = 8, - NormalizedShort4 = 9, - HalfVector2 = 10, - HalfVector4 = 11, -}; - -class ECSVertexElementFormat -{ -public: - static const char* ToString(CSVertexElementFormat enumValue) - { - switch (enumValue) - { - case Single: return "Single"; - case Vector2: return "Vector2"; - case Vector3: return "Vector3"; - case Vector4: return "Vector4"; - case Color: return "Color"; - case Byte4: return "Byte4"; - case Short2: return "Short2"; - case Short4: return "Short4"; - case NormalizedShort2: return "NormalizedShort2"; - case NormalizedShort4: return "NormalizedShort4"; - case HalfVector2: return "HalfVector2"; - case HalfVector4: return "HalfVector4"; - } - - return "Unknown Value"; - } -}; - -enum CSVertexElementUsage : csint -{ - Position = 0, - Color = 1, - TextureCoordinate = 2, - Normal = 3, - Binormal = 4, - Tangent = 5, - BlendIndices = 6, - BlendWeight = 7, - Depth = 8, - Fog = 9, - PointSize = 10, - Sample = 11, - TessellateFactor = 12, -}; - -class ECSVertexElementUsage -{ -public: - static const char* ToString(CSVertexElementUsage enumValue) - { - switch (enumValue) - { - case Position: return "Position"; - case Color: return "Color"; - case TextureCoordinate: return "TextureCoordinate"; - case Normal: return "Normal"; - case Binormal: return "Binormal"; - case Tangent: return "Tangent"; - case BlendIndices: return "BlendIndices"; - case BlendWeight: return "BlendWeight"; - case Depth: return "Depth"; - case Fog: return "Fog"; - case PointSize: return "PointSize"; - case Sample: return "Sample"; - case TessellateFactor: return "TessellateFactor"; - } - - return "Unknown Value"; - } -}; - -enum CSAudioChannels : csint -{ - Mono = 1, - Stereo = 2, -}; - -class ECSAudioChannels -{ -public: - static const char* ToString(CSAudioChannels enumValue) - { - switch (enumValue) - { - case Mono: return "Mono"; - case Stereo: return "Stereo"; - } - - return "Unknown Value"; - } -}; - -enum CSMicrophoneState : csint -{ - Started = 0, - Stopped = 1, -}; - -class ECSMicrophoneState -{ -public: - static const char* ToString(CSMicrophoneState enumValue) - { - switch (enumValue) - { - case Started: return "Started"; - case Stopped: return "Stopped"; - } - - return "Unknown Value"; - } -}; - -enum CSSoundState : csint -{ - Playing = 0, - Paused = 1, - Stopped = 2, -}; - -class ECSSoundState -{ -public: - static const char* ToString(CSSoundState enumValue) - { - switch (enumValue) - { - case Playing: return "Playing"; - case Paused: return "Paused"; - case Stopped: return "Stopped"; - } - - return "Unknown Value"; - } -}; - -enum CSAudioStopOptions : csint -{ - AsAuthored = 0, - Immediate = 1, -}; - -class ECSAudioStopOptions -{ -public: - static const char* ToString(CSAudioStopOptions enumValue) - { - switch (enumValue) - { - case AsAuthored: return "AsAuthored"; - case Immediate: return "Immediate"; - } - - return "Unknown Value"; - } -}; - -enum CSCrossfadeType : csint -{ - Linear = 0, - Logarithmic = 1, - EqualPower = 2, -}; - -class ECSCrossfadeType -{ -public: - static const char* ToString(CSCrossfadeType enumValue) - { - switch (enumValue) - { - case Linear: return "Linear"; - case Logarithmic: return "Logarithmic"; - case EqualPower: return "EqualPower"; - } - - return "Unknown Value"; - } -}; - -enum CSFilterMode : csint -{ - LowPass = 0, - BandPass = 1, - HighPass = 2, -}; - -class ECSFilterMode -{ -public: - static const char* ToString(CSFilterMode enumValue) - { - switch (enumValue) - { - case LowPass: return "LowPass"; - case BandPass: return "BandPass"; - case HighPass: return "HighPass"; - } - - return "Unknown Value"; - } -}; - -enum CSMaxInstanceBehavior : csint -{ - FailToPlay = 0, - Queue = 1, - ReplaceOldest = 2, - ReplaceQuietest = 3, - ReplaceLowestPriority = 4, -}; - -class ECSMaxInstanceBehavior -{ -public: - static const char* ToString(CSMaxInstanceBehavior enumValue) - { - switch (enumValue) - { - case FailToPlay: return "FailToPlay"; - case Queue: return "Queue"; - case ReplaceOldest: return "ReplaceOldest"; - case ReplaceQuietest: return "ReplaceQuietest"; - case ReplaceLowestPriority: return "ReplaceLowestPriority"; - } - - return "Unknown Value"; - } -}; - -enum CSMiniFormatTag : csint -{ - Pcm = 0, - Xma = 1, - Xma = 1, - Adpcm = 2, - Wma = 3, -}; - -class ECSMiniFormatTag -{ -public: - static const char* ToString(CSMiniFormatTag enumValue) - { - switch (enumValue) - { - case Pcm: return "Pcm"; - case Xma: return "Xma"; - case Xma: return "Xma"; - case Adpcm: return "Adpcm"; - case Wma: return "Wma"; - } - - return "Unknown Value"; - } -}; - -enum CSVariationType : csint -{ - Ordered = 0, - OrderedFromRandom = 1, - Random = 2, - RandomNoImmediateRepeats = 3, - Shuffle = 4, -}; - -class ECSVariationType -{ -public: - static const char* ToString(CSVariationType enumValue) - { - switch (enumValue) - { - case Ordered: return "Ordered"; - case OrderedFromRandom: return "OrderedFromRandom"; - case Random: return "Random"; - case RandomNoImmediateRepeats: return "RandomNoImmediateRepeats"; - case Shuffle: return "Shuffle"; - } - - return "Unknown Value"; - } -}; - -enum CSRpcParameter : csint -{ - Volume = 0, - Pitch = 1, - ReverbSend = 2, - FilterFrequency = 3, - FilterQFactor = 4, - NumParameters = 5, -}; - -class ECSRpcParameter -{ -public: - static const char* ToString(CSRpcParameter enumValue) - { - switch (enumValue) - { - case Volume: return "Volume"; - case Pitch: return "Pitch"; - case ReverbSend: return "ReverbSend"; - case FilterFrequency: return "FilterFrequency"; - case FilterQFactor: return "FilterQFactor"; - case NumParameters: return "NumParameters"; + case Depth16: return "Depth16"; + case Depth24: return "Depth24"; + case Depth24Stencil8: return "Depth24Stencil8"; } return "Unknown Value"; } }; -enum CSRpcPointType : csint +enum MGShaderStage : mgint { - Linear = 0, - Fast = 1, - Slow = 2, - SinCos = 3, + Vertex = 0, + Pixel = 1, }; -class ECSRpcPointType +class EMGShaderStage { public: - static const char* ToString(CSRpcPointType enumValue) + static const char* ToString(MGShaderStage enumValue) { switch (enumValue) { - case Linear: return "Linear"; - case Fast: return "Fast"; - case Slow: return "Slow"; - case SinCos: return "SinCos"; + case Vertex: return "Vertex"; + case Pixel: return "Pixel"; } return "Unknown Value"; diff --git a/src/monogame/include/csharp_structs.h b/src/monogame/include/csharp_structs.h new file mode 100644 index 00000000000..367e7bafbaa --- /dev/null +++ b/src/monogame/include/csharp_structs.h @@ -0,0 +1,14 @@ +// +// This code is auto generated, don't modify it by hand. +// To regenerate it run: Tools/MonoGame.Generator.CTypes +// + +#pragma once + +#include "csharp_common.h" + +struct MGG_GraphicsDevice_Caps +{ +public: +}; + diff --git a/src/monogame/null_device/MGG.cpp b/src/monogame/null_device/MGG.cpp new file mode 100644 index 00000000000..ebe9816fea4 --- /dev/null +++ b/src/monogame/null_device/MGG.cpp @@ -0,0 +1,111 @@ +// MonoGame - Copyright (C) The MonoGame Team +// This file is subject to the terms and conditions defined in +// file 'LICENSE.txt', which is part of this source code package. + +#include "csharp_MGG.h" + +#include +#include + + +struct MGG_GraphicsDevice +{ + std::vector buffers; + std::vector textures; +}; + + +struct MGG_Buffer +{ + mgint length; +}; + +struct MGG_Texture +{ + MGSurfaceFormat format; + mgint width; + mgint height; + mgint levels; +}; + + +MGG_GraphicsDevice* MGG_GraphicsDevice_Create() +{ + auto device = new MGG_GraphicsDevice(); + return device; +} + +void MGG_GraphicsDevice_GetCaps(MGG_GraphicsDevice* device, MGG_GraphicsDevice_Caps& caps) +{ + assert(device != nullptr); +} + +void MGG_GraphicsDevice_ResetBackbuffer(MGG_GraphicsDevice* device, mgint width, mgint height, MGSurfaceFormat color, MGDepthFormat depth) +{ + assert(device != nullptr); +} + +mgint MGG_GraphicsDevice_BeginFrame(MGG_GraphicsDevice* device) +{ + assert(device != nullptr); + return 0; +} + +void MGG_GraphicsDevice_Present(MGG_GraphicsDevice* device, mgint currentFrame) +{ + assert(device != nullptr); +} + +void MGG_GraphicsDevice_BindConstantBuffer(MGG_GraphicsDevice* device, MGShaderStage stage, mgint slot, MGG_Buffer* buffer) +{ + assert(device != nullptr); +} + +MGG_Buffer* MGG_Buffer_Create(MGG_GraphicsDevice* device, mgint length) +{ + assert(device != nullptr); + + auto buffer = new MGG_Buffer(); + buffer->length = length; + + device->buffers.push_back(buffer); + + return buffer; +} + +void MGG_Buffer_SetData(MGG_GraphicsDevice* device, MGG_Buffer*& buffer, mgint offset, mgbyte* data, mgint length, mgbool discard) +{ + assert(device != nullptr); +} + +void MGG_Buffer_Destroy(MGG_GraphicsDevice* device, MGG_Buffer* buffer) +{ + assert(device != nullptr); + + std::remove(device->buffers.begin(), device->buffers.end(), buffer); + delete buffer; +} + +MGG_Texture* MGG_Texture_Create(MGG_GraphicsDevice* device, MGSurfaceFormat format, mgint width, mgint height, mgint levels) +{ + assert(device != nullptr); + + auto texture = new MGG_Texture(); + texture->format = format; + texture->width = width; + texture->height = height; + texture->levels = levels; + + device->textures.push_back(texture); + + return texture; +} + +void MGG_Texture_Destroy(MGG_GraphicsDevice* device, MGG_Texture* texture) +{ + assert(device != nullptr); + + std::remove(device->textures.begin(), device->textures.end(), texture); + delete texture; +} + diff --git a/src/monogame/null_device/null_device.vcxproj b/src/monogame/null_device/null_device.vcxproj new file mode 100644 index 00000000000..9fc0f795289 --- /dev/null +++ b/src/monogame/null_device/null_device.vcxproj @@ -0,0 +1,146 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {3482ddfe-a5be-4261-868f-a269f2b20dac} + nulldevice + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\include + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\include + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\include + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\include + + + Console + true + true + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/monogame/null_device/null_device.vcxproj.filters b/src/monogame/null_device/null_device.vcxproj.filters new file mode 100644 index 00000000000..44dc5a1d5d3 --- /dev/null +++ b/src/monogame/null_device/null_device.vcxproj.filters @@ -0,0 +1,28 @@ + + + + + include + + + include + + + include + + + include + + + include + + + + + + + + {c518f7c6-d7c8-4bc7-8683-1813c63d8d7f} + + + \ No newline at end of file