From e8fedc8bfffe871e8d54ab178592dc636f478ab9 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 31 Oct 2024 17:15:06 +0800 Subject: [PATCH] feat: update BMapSharp - update virtools type defines in BMapSharp. expand its ctor for convenient usage. - finish BMMaterial bindings. - create a generic value getter setter for convenient calling. - fix codegen error of BMapSharp (accident fallthrough for CKBYTE type and wrong marshal type for enum type). --- BMapBindings/BMapSharp/BMapSharp/BMap.cs | 60 ++++----- .../BMapSharp/BMapSharp/BMapWrapper.cs | 125 ++++++++++-------- .../BMapSharp/BMapSharp/VirtoolsTypes.cs | 47 ++++--- .../BMapSharp/BMapSharpTestbench/Program.cs | 22 +++ COMPILE.md | 6 +- CodeGen/BMapBindings/CSharpWriter.java | 8 +- 6 files changed, 160 insertions(+), 108 deletions(-) diff --git a/BMapBindings/BMapSharp/BMapSharp/BMap.cs b/BMapBindings/BMapSharp/BMapSharp/BMap.cs index 888d1b0..cf304e5 100644 --- a/BMapBindings/BMapSharp/BMapSharp/BMap.cs +++ b/BMapBindings/BMapSharp/BMapSharp/BMap.cs @@ -293,7 +293,7 @@ namespace BMapSharp { #region Function Defines // ##### GENERATED FUNCTIONS BEGIN ##### - + /// BMInit /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMInit", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] @@ -336,7 +336,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMFile_Save", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMFile_Save([In, MarshalAs(UnmanagedType.SysInt)] IntPtr map_file, [In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(BMStringMarshaler), MarshalCookie = "In")] string file_name, [In, MarshalAs(UnmanagedType.U4)] uint texture_save_opt, [In, MarshalAs(UnmanagedType.U1)] bool use_compress, [In, MarshalAs(UnmanagedType.I4)] int compreess_level); + internal static extern bool BMFile_Save([In, MarshalAs(UnmanagedType.SysInt)] IntPtr map_file, [In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(BMStringMarshaler), MarshalCookie = "In")] string file_name, [In, MarshalAs(UnmanagedType.U4)] CK_TEXTURE_SAVEOPTIONS texture_save_opt, [In, MarshalAs(UnmanagedType.U1)] bool use_compress, [In, MarshalAs(UnmanagedType.I4)] int compreess_level); /// BMFile_Free /// Type: BMap::BMFile*. /// True if no error, otherwise False. @@ -636,7 +636,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMTexture_GetSaveOptions", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMTexture_GetSaveOptions([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_saveopt); + internal static extern bool BMTexture_GetSaveOptions([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out CK_TEXTURE_SAVEOPTIONS out_saveopt); /// BMTexture_SetSaveOptions /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -644,7 +644,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMTexture_SetSaveOptions", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMTexture_SetSaveOptions([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint saveopt); + internal static extern bool BMTexture_SetSaveOptions([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] CK_TEXTURE_SAVEOPTIONS saveopt); /// BMTexture_GetVideoFormat /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -652,7 +652,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMTexture_GetVideoFormat", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMTexture_GetVideoFormat([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_vfmt); + internal static extern bool BMTexture_GetVideoFormat([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VX_PIXELFORMAT out_vfmt); /// BMTexture_SetVideoFormat /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -660,7 +660,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMTexture_SetVideoFormat", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMTexture_SetVideoFormat([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint vfmt); + internal static extern bool BMTexture_SetVideoFormat([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VX_PIXELFORMAT vfmt); /// BMMaterial_GetDiffuse /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -780,7 +780,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetTextureBlendMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetTextureBlendMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetTextureBlendMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXTEXTURE_BLENDMODE out_val); /// BMMaterial_SetTextureBlendMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -788,7 +788,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetTextureBlendMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetTextureBlendMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetTextureBlendMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXTEXTURE_BLENDMODE val); /// BMMaterial_GetTextureMinMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -796,7 +796,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetTextureMinMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetTextureMinMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetTextureMinMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXTEXTURE_FILTERMODE out_val); /// BMMaterial_SetTextureMinMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -804,7 +804,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetTextureMinMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetTextureMinMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetTextureMinMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXTEXTURE_FILTERMODE val); /// BMMaterial_GetTextureMagMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -812,7 +812,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetTextureMagMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetTextureMagMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetTextureMagMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXTEXTURE_FILTERMODE out_val); /// BMMaterial_SetTextureMagMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -820,7 +820,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetTextureMagMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetTextureMagMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetTextureMagMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXTEXTURE_FILTERMODE val); /// BMMaterial_GetTextureAddressMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -828,7 +828,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetTextureAddressMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetTextureAddressMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetTextureAddressMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXTEXTURE_ADDRESSMODE out_val); /// BMMaterial_SetTextureAddressMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -836,7 +836,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetTextureAddressMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetTextureAddressMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetTextureAddressMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXTEXTURE_ADDRESSMODE val); /// BMMaterial_GetSourceBlend /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -844,7 +844,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetSourceBlend", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetSourceBlend([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetSourceBlend([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXBLEND_MODE out_val); /// BMMaterial_SetSourceBlend /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -852,7 +852,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetSourceBlend", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetSourceBlend([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetSourceBlend([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXBLEND_MODE val); /// BMMaterial_GetDestBlend /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -860,7 +860,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetDestBlend", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetDestBlend([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetDestBlend([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXBLEND_MODE out_val); /// BMMaterial_SetDestBlend /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -868,7 +868,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetDestBlend", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetDestBlend([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetDestBlend([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXBLEND_MODE val); /// BMMaterial_GetFillMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -876,7 +876,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetFillMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetFillMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetFillMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXFILL_MODE out_val); /// BMMaterial_SetFillMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -884,7 +884,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetFillMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetFillMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetFillMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXFILL_MODE val); /// BMMaterial_GetShadeMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -892,7 +892,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetShadeMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetShadeMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetShadeMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXSHADE_MODE out_val); /// BMMaterial_SetShadeMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -900,7 +900,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetShadeMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetShadeMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetShadeMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXSHADE_MODE val); /// BMMaterial_GetAlphaTestEnabled /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -988,7 +988,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetAlphaRef", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetAlphaRef([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetAlphaRef([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U1)] out byte out_val); /// BMMaterial_SetAlphaRef /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -996,7 +996,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetAlphaRef", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetAlphaRef([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetAlphaRef([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U1)] byte val); /// BMMaterial_GetAlphaFunc /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -1004,7 +1004,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetAlphaFunc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetAlphaFunc([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetAlphaFunc([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXCMPFUNC out_val); /// BMMaterial_SetAlphaFunc /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -1012,7 +1012,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetAlphaFunc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetAlphaFunc([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetAlphaFunc([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXCMPFUNC val); /// BMMaterial_GetZFunc /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -1020,7 +1020,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_GetZFunc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_GetZFunc([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_val); + internal static extern bool BMMaterial_GetZFunc([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXCMPFUNC out_val); /// BMMaterial_SetZFunc /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -1028,7 +1028,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMaterial_SetZFunc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMaterial_SetZFunc([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint val); + internal static extern bool BMMaterial_SetZFunc([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXCMPFUNC val); /// BMMesh_GetLitMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -1036,7 +1036,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMesh_GetLitMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMesh_GetLitMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out uint out_mode); + internal static extern bool BMMesh_GetLitMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [Out, MarshalAs(UnmanagedType.U4)] out VXMESH_LITMODE out_mode); /// BMMesh_SetLitMode /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. @@ -1044,7 +1044,7 @@ namespace BMapSharp { /// True if no error, otherwise False. [DllImport(g_DllName, EntryPoint = "BMMesh_SetLitMode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, ExactSpelling = true)] [return: MarshalAs(UnmanagedType.U1)] - internal static extern bool BMMesh_SetLitMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] uint mode); + internal static extern bool BMMesh_SetLitMode([In, MarshalAs(UnmanagedType.SysInt)] IntPtr bmfile, [In, MarshalAs(UnmanagedType.U4)] uint objid, [In, MarshalAs(UnmanagedType.U4)] VXMESH_LITMODE mode); /// BMMesh_GetVertexCount /// Type: BMap::BMFile*. The pointer to corresponding BMFile. /// Type: LibCmo::CK2::CK_ID. The CKID of object you accessing. diff --git a/BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs b/BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs index 2a4bbca..dfdaf8e 100644 --- a/BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs +++ b/BMapBindings/BMapSharp/BMapSharp/BMapWrapper.cs @@ -45,7 +45,7 @@ namespace BMapSharp.BMapWrapper { var stride = Marshal.SizeOf(); var itor = iem.GetEnumerator(); for (uint i = 0; i < count; ++i) { - BMapException.ThrowIfFailed(itor.MoveNext()); + if (!itor.MoveNext()) throw new BMapException("The length of given data is too short when assigning struct array."); Marshal.StructureToPtr(itor.Current, pstruct, false); pstruct += stride; } @@ -194,84 +194,105 @@ namespace BMapSharp.BMapWrapper { public override string ToString() => $"{this.handle}, {m_CKID}"; #endregion + + #region Subclass Utilities + + protected delegate bool FctGenericValueGetter(IntPtr bmf, uint id, out T val); + protected delegate bool FctGenericValueSetter(IntPtr bmf, uint id, T val); + protected T getGenericValue(FctGenericValueGetter fct) { + BMapException.ThrowIfFailed(fct(getPointer(), getCKID(), out T out_val)); + return out_val; + } + protected void setGenericValue(FctGenericValueSetter fct, T val) { + BMapException.ThrowIfFailed(fct(getPointer(), getCKID(), val)); + } + + #endregion } public class BMObject : AbstractCKObject { internal BMObject(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } - public string GetName() { - BMapException.ThrowIfFailed(BMap.BMObject_GetName(getPointer(), getCKID(), out string out_name)); - return out_name; - } - public void SetName(string name) { - BMapException.ThrowIfFailed(BMap.BMObject_SetName(getPointer(), getCKID(), name)); - } + public string GetName() => getGenericValue(BMap.BMObject_GetName); + public void SetName(string name) => setGenericValue(BMap.BMObject_SetName, name); } public class BMTexture : BMObject { internal BMTexture(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } - public string GetFileName() { - BMapException.ThrowIfFailed(BMap.BMTexture_GetFileName(getPointer(), getCKID(), out string out_filename)); - return out_filename; - } + public string GetFileName() => getGenericValue(BMap.BMTexture_GetFileName); public void LoadImage(string filepath) { BMapException.ThrowIfFailed(BMap.BMTexture_LoadImage(getPointer(), getCKID(), filepath)); } - public void SaveImage(string filepath) { BMapException.ThrowIfFailed(BMap.BMTexture_SaveImage(getPointer(), getCKID(), filepath)); } - public CK_TEXTURE_SAVEOPTIONS GetSaveOptions() { - BMapException.ThrowIfFailed(BMap.BMTexture_GetSaveOptions(getPointer(), getCKID(), out uint out_saveopt)); - return (CK_TEXTURE_SAVEOPTIONS)out_saveopt; - } - - public void SetSaveOptions(CK_TEXTURE_SAVEOPTIONS opt) { - BMapException.ThrowIfFailed(BMap.BMTexture_SetSaveOptions(getPointer(), getCKID(), (uint)opt)); - } - - public VX_PIXELFORMAT GetVideoFormat() { - BMapException.ThrowIfFailed(BMap.BMTexture_GetVideoFormat(getPointer(), getCKID(), out uint out_vfmt)); - return (VX_PIXELFORMAT)out_vfmt; - } - - public void SetVideoFormat(VX_PIXELFORMAT vfmt) { - BMapException.ThrowIfFailed(BMap.BMTexture_SetVideoFormat(getPointer(), getCKID(), (uint)vfmt)); - } + public CK_TEXTURE_SAVEOPTIONS GetSaveOptions() => getGenericValue(BMap.BMTexture_GetSaveOptions); + public void SetSaveOptions(CK_TEXTURE_SAVEOPTIONS opt) => setGenericValue(BMap.BMTexture_SetSaveOptions, opt); + public VX_PIXELFORMAT GetVideoFormat() => getGenericValue(BMap.BMTexture_GetVideoFormat); + public void SetVideoFormat(VX_PIXELFORMAT vfmt) => setGenericValue(BMap.BMTexture_SetVideoFormat, vfmt); } public class BMMaterial : BMObject { internal BMMaterial(IntPtr raw_pointer, uint ckid) : base(raw_pointer, ckid) { } - private delegate bool FctVxColorSetter(IntPtr bmf, uint id, VxColor col); - private delegate bool FctVxColorGetter(IntPtr bmf, uint id, out VxColor col); - private VxColor getVxColor(FctVxColorGetter fct) { - BMapException.ThrowIfFailed(fct(getPointer(), getCKID(), out VxColor out_col)); - return out_col; + public VxColor GetDiffuse() => getGenericValue(BMap.BMMaterial_GetDiffuse); + public void SetDiffuse(VxColor col) => setGenericValue(BMap.BMMaterial_SetDiffuse, col); + public VxColor GetAmbient() => getGenericValue(BMap.BMMaterial_GetAmbient); + public void SetAmbient(VxColor col) => setGenericValue(BMap.BMMaterial_SetAmbient, col); + public VxColor GetSpecular() => getGenericValue(BMap.BMMaterial_GetSpecular); + public void SetSpecular(VxColor col) => setGenericValue(BMap.BMMaterial_SetSpecular, col); + public VxColor GetEmissive() => getGenericValue(BMap.BMMaterial_GetEmissive); + public void SetEmissive(VxColor col) => setGenericValue(BMap.BMMaterial_SetEmissive, col); + + public float GetSpecularPower() => getGenericValue(BMap.BMMaterial_GetSpecularPower); + public void SetSpecularPower(float val) => setGenericValue(BMap.BMMaterial_SetSpecularPower, val); + + public VxColor GetTextureBorderColor() { + BMapException.ThrowIfFailed(BMap.BMMaterial_GetTextureBorderColor(getPointer(), getCKID(), out uint out_val)); + return new VxColor(out_val); } - private void setVxColor(FctVxColorSetter fct, VxColor col) { - BMapException.ThrowIfFailed(fct(getPointer(), getCKID(), col)); + public void SetTextureBorderColor(VxColor col) { + BMapException.ThrowIfFailed(BMap.BMMaterial_SetTextureBorderColor(getPointer(), getCKID(), col.ToDword())); } - public VxColor GetDiffuse() => getVxColor(BMap.BMMaterial_GetDiffuse); - public void SetDiffuse(VxColor col) => setVxColor(BMap.BMMaterial_SetDiffuse, col); - public VxColor GetAmbient() => getVxColor(BMap.BMMaterial_GetAmbient); - public void SetAmbient(VxColor col) => setVxColor(BMap.BMMaterial_SetAmbient, col); - public VxColor GetSpecular() => getVxColor(BMap.BMMaterial_GetSpecular); - public void SetSpecular(VxColor col) => setVxColor(BMap.BMMaterial_SetSpecular, col); - public VxColor GetEmissive() => getVxColor(BMap.BMMaterial_GetEmissive); - public void SetEmissive(VxColor col) => setVxColor(BMap.BMMaterial_SetEmissive, col); + public VXTEXTURE_BLENDMODE GetTextureBlendMode() => getGenericValue(BMap.BMMaterial_GetTextureBlendMode); + public void SetTextureBlendMode(VXTEXTURE_BLENDMODE val) => setGenericValue(BMap.BMMaterial_SetTextureBlendMode, val); + public VXTEXTURE_FILTERMODE GetTextureMinMode() => getGenericValue(BMap.BMMaterial_GetTextureMinMode); + public void SetTextureMinMode(VXTEXTURE_FILTERMODE val) => setGenericValue(BMap.BMMaterial_SetTextureMinMode, val); + public VXTEXTURE_FILTERMODE GetTextureMagMode() => getGenericValue(BMap.BMMaterial_GetTextureMagMode); + public void SetTextureMagMode(VXTEXTURE_FILTERMODE val) => setGenericValue(BMap.BMMaterial_SetTextureMagMode, val); + public VXTEXTURE_ADDRESSMODE GetTextureAddressMode() => getGenericValue(BMap.BMMaterial_GetTextureAddressMode); + public void SetTextureAddressMode(VXTEXTURE_ADDRESSMODE val) => setGenericValue(BMap.BMMaterial_SetTextureAddressMode, val); + public VXBLEND_MODE GetSourceBlend() => getGenericValue(BMap.BMMaterial_GetSourceBlend); + public void SetSourceBlend(VXBLEND_MODE val) => setGenericValue(BMap.BMMaterial_SetSourceBlend, val); + public VXBLEND_MODE GetDestBlend() => getGenericValue(BMap.BMMaterial_GetDestBlend); + public void SetDestBlend(VXBLEND_MODE val) => setGenericValue(BMap.BMMaterial_SetDestBlend, val); + public VXFILL_MODE GetFillMode() => getGenericValue(BMap.BMMaterial_GetFillMode); + public void SetFillMode(VXFILL_MODE val) => setGenericValue(BMap.BMMaterial_SetFillMode, val); + public VXSHADE_MODE GetShadeMode() => getGenericValue(BMap.BMMaterial_GetShadeMode); + public void SetShadeMode(VXSHADE_MODE val) => setGenericValue(BMap.BMMaterial_SetShadeMode, val); - public float GetSpecularPower() { - BMapException.ThrowIfFailed(BMap.BMMaterial_GetSpecularPower(getPointer(), getCKID(), out float out_val)); - return out_val; - } - public void SetSpecularPower(float val) { - BMapException.ThrowIfFailed(BMap.BMMaterial_SetSpecularPower(getPointer(), getCKID(), val)); - } + public bool GetAlphaTestEnabled() => getGenericValue(BMap.BMMaterial_GetAlphaTestEnabled); + public void SetAlphaTestEnabled(bool val) => setGenericValue(BMap.BMMaterial_SetAlphaTestEnabled, val); + public bool GetAlphaBlendEnabled() => getGenericValue(BMap.BMMaterial_GetAlphaBlendEnabled); + public void SetAlphaBlendEnabled(bool val) => setGenericValue(BMap.BMMaterial_SetAlphaBlendEnabled, val); + public bool GetPerspectiveCorrectionEnabled() => getGenericValue(BMap.BMMaterial_GetPerspectiveCorrectionEnabled); + public void SetPerspectiveCorrectionEnabled(bool val) => setGenericValue(BMap.BMMaterial_SetPerspectiveCorrectionEnabled, val); + public bool GetZWriteEnabled() => getGenericValue(BMap.BMMaterial_GetZWriteEnabled); + public void SetZWriteEnabled(bool val) => setGenericValue(BMap.BMMaterial_SetZWriteEnabled, val); + public bool GetTwoSidedEnabled() => getGenericValue(BMap.BMMaterial_GetTwoSidedEnabled); + public void SetTwoSidedEnabled(bool val) => setGenericValue(BMap.BMMaterial_SetTwoSidedEnabled, val); + + public byte GetAlphaRef() => getGenericValue(BMap.BMMaterial_GetAlphaRef); + public void SetAlphaRef(byte val) => setGenericValue(BMap.BMMaterial_SetAlphaRef, val); + + public VXCMPFUNC GetAlphaFunc() => getGenericValue(BMap.BMMaterial_GetAlphaFunc); + public void SetAlphaFunc(VXCMPFUNC val) => setGenericValue(BMap.BMMaterial_SetAlphaFunc, val); + public VXCMPFUNC GetZFunc() => getGenericValue(BMap.BMMaterial_GetZFunc); + public void SetZFunc(VXCMPFUNC val) => setGenericValue(BMap.BMMaterial_SetZFunc, val); } diff --git a/BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs b/BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs index df4374a..0ec618b 100644 --- a/BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs +++ b/BMapBindings/BMapSharp/BMapSharp/VirtoolsTypes.cs @@ -15,12 +15,14 @@ namespace BMapSharp.VirtoolsTypes { public float X, Y; public VxVector2(float _x = 0.0f, float _y = 0.0f) { - X = _x; - Y = _y; + X = _x; Y = _y; } + public VxVector2(Vector2 vec) { + FromManaged(vec); + } + public void FromManaged(Vector2 vec) { - X = vec.X; - Y = vec.Y; + X = vec.X; Y = vec.Y; } public Vector2 ToManaged() { return new Vector2(X, Y); @@ -33,14 +35,14 @@ namespace BMapSharp.VirtoolsTypes { public float X, Y, Z; public VxVector3(float _x = 0.0f, float _y = 0.0f, float _z = 0.0f) { - X = _x; - Y = _y; - Z = _z; + X = _x; Y = _y; Z = _z; } + public VxVector3(Vector3 vec) { + FromManaged(vec); + } + public void FromManaged(Vector3 vec) { - X = vec.X; - Y = vec.Y; - Z = vec.Z; + X = vec.X; Y = vec.Y; Z = vec.Z; } public Vector3 ToManaged() { return new Vector3(X, Y, Z); @@ -53,26 +55,28 @@ namespace BMapSharp.VirtoolsTypes { public float A, R, G, B; public VxColor(float _r, float _g, float _b, float _a) { - A = _a; - R = _r; - G = _g; - B = _b; + A = _a; R = _r; G = _g; B = _b; Regulate(); } + public VxColor(Vector4 col) { + FromManagedRGBA(col); + } + public VxColor(Vector3 col) { + FromManagedRGB(col); + } + public VxColor(uint val) { + FromDword(val); + } + public void FromManagedRGBA(Vector4 col) { - R = col.X; - G = col.Y; - B = col.Z; - A = col.W; + R = col.X; G = col.Y; B = col.Z; A = col.W; Regulate(); } public Vector4 ToManagedRGBA() { return new Vector4(R, G, B, A); } public void FromManagedRGB(Vector3 col) { - R = col.X; - G = col.Y; - B = col.Z; + R = col.X; G = col.Y; B = col.Z; A = 1.0f; Regulate(); } public Vector3 ToManagedRGB() { @@ -101,6 +105,7 @@ namespace BMapSharp.VirtoolsTypes { val |= (uint)(B * 255.0f); return val; } + public static float ClampFactor(float factor) { return System.Math.Clamp(factor, 0.0f, 1.0f); } diff --git a/BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs b/BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs index e9323af..a55dcea 100644 --- a/BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs +++ b/BMapBindings/BMapSharp/BMapSharpTestbench/Program.cs @@ -55,7 +55,29 @@ namespace BMapSharpTestbench { Console.WriteLine($"\tAmbient: {mtl.GetAmbient().ToManagedRGBA()}"); Console.WriteLine($"\tSpecular: {mtl.GetSpecular().ToManagedRGBA()}"); Console.WriteLine($"\tEmissive: {mtl.GetEmissive().ToManagedRGBA()}"); + Console.WriteLine($"\tSpecular Power: {mtl.GetSpecularPower()}"); + + Console.WriteLine($"\tTexture Border Color: {mtl.GetTextureBorderColor().ToManagedRGBA()}"); + + Console.WriteLine($"\tTexture Blend Mode: {mtl.GetTextureBlendMode()}"); + Console.WriteLine($"\tTexture Min Mode: {mtl.GetTextureMinMode()}"); + Console.WriteLine($"\tTexture Mag Mode: {mtl.GetTextureMagMode()}"); + Console.WriteLine($"\tSource Blend: {mtl.GetSourceBlend()}"); + Console.WriteLine($"\tDest Blend: {mtl.GetDestBlend()}"); + Console.WriteLine($"\tFill Mode: {mtl.GetFillMode()}"); + Console.WriteLine($"\tShade Mode: {mtl.GetShadeMode()}"); + + Console.WriteLine($"\tAlpha Test Enabled: {mtl.GetAlphaTestEnabled()}"); + Console.WriteLine($"\tAlpha Blend Enabled: {mtl.GetAlphaBlendEnabled()}"); + Console.WriteLine($"\tPerspective Correction Enabled: {mtl.GetPerspectiveCorrectionEnabled()}"); + Console.WriteLine($"\tZ Write Enabled: {mtl.GetZWriteEnabled()}"); + Console.WriteLine($"\tTwo Sided Enabled: {mtl.GetTwoSidedEnabled()}"); + + Console.WriteLine($"\tAlpha Ref: {mtl.GetAlphaRef()}"); + + Console.WriteLine($"\tAlpha Func: {mtl.GetAlphaFunc()}"); + Console.WriteLine($"\tZ Func: {mtl.GetZFunc()}"); } // Console.WriteLine("===== Textures ====="); diff --git a/COMPILE.md b/COMPILE.md index d8bd03c..b50cfa3 100644 --- a/COMPILE.md +++ b/COMPILE.md @@ -29,7 +29,7 @@ Please note if your final program or dynamic library is provided for end user, p ### stb -You should clone stb repository first, then switch to a specific commit hash `5736b15f7ea0ffb08dd38af21067c314d6a3aae9`. In ideally scenario, people like to choose the latest commit. However, I hardly update this dependency so the latest commit is not work. +You should clone stb repository first, then switch to a specific commit hash `5736b15f7ea0ffb08dd38af21067c314d6a3aae9`. In ideally scenario, people like to choose the latest commit. However, I not frequently update this dependency. ### zlib @@ -41,7 +41,7 @@ If you are running on non-Windows system. You usually do not need to do anything ### Directory Hierarchy -First, create subdirectory `Bin/build` and `Bin/install`. +First, create subdirectory `Bin/build` and `Bin/install` at the root directory of libcmo21. ### Configuration @@ -60,7 +60,7 @@ The arguments in command should be replaced by: The switches in command can be switched as you wish: * `NEMO_BUILD_UNVIRT`: Build `Unvirt`, a command line application debugging Virtools files. -* `NEMO_BUILD_BMAP`: Build `BMap`, a dynamic library specific used for loading Ballance map file. +* `NEMO_BUILD_BMAP`: Build `BMap`, a dynamic library specific used for loading Ballance map file. If you are coming from my another project [BallanceBlenderPlugin](https://github.com/yyc12345/BallanceBlenderHelper), this is what you need. * `NEMO_BUILD_DOC`: Build the document of libcmo21. ### Build diff --git a/CodeGen/BMapBindings/CSharpWriter.java b/CodeGen/BMapBindings/CSharpWriter.java index 55406ba..5c4fee3 100644 --- a/CodeGen/BMapBindings/CSharpWriter.java +++ b/CodeGen/BMapBindings/CSharpWriter.java @@ -118,6 +118,7 @@ public class CSharpWriter { ret.mMarshalAs = "UnmanagedType.SysInt"; ret.mCsType = "IntPtr"; } + break; case "CK_ID": if (vt_pointer_level == 0) { ret.mMarshalAs = "UnmanagedType.U4"; @@ -195,11 +196,14 @@ public class CSharpWriter { case "VXSHADE_MODE": case "VXCMPFUNC": case "VXMESH_LITMODE": - // all enum share the same underlying type. + // all enum type use the same strategy if (vt_pointer_level == 0) { + // all enum type should be marshaled as its underlying type + // but we can use its name in C# directly. ret.mMarshalAs = "UnmanagedType.U4"; - ret.mCsType = "uint"; + ret.mCsType = vt_base_type; } else { + // for pointer type, use IntPtr instead. ret.mMarshalAs = "UnmanagedType.SysInt"; ret.mCsType = "IntPtr"; }