From e938ddf88c6becc98fd322e392fad60ed6a99445 Mon Sep 17 00:00:00 2001
From: Sebastian Marketsmueller
<36425933+sebastianmunity3d@users.noreply.github.com>
Date: Wed, 10 Jul 2019 21:27:03 -0700
Subject: [PATCH] c# bindings: bring back bool as params, only replace by byte
in structs. (#1813)
* fix some c# bindings gen: support arrays, move chars to bytes, marshal char* return correctly
* bring back bool as parameters only
---
bindings/cs/bgfx.cs | 58 ++++++++++++++++++++---------------------
scripts/bindings-cs.lua | 19 ++++++++------
2 files changed, 40 insertions(+), 37 deletions(-)
diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs
index bcb4820b5..b368493e2 100644
--- a/bindings/cs/bgfx.cs
+++ b/bindings/cs/bgfx.cs
@@ -922,7 +922,7 @@ public static partial class bgfx
/// Packaging rule for vertexPack, vertexUnpack, and vertexConvert for AttribType::Uint8 and AttribType::Int16. Unpacking code must be implemented inside vertex shader.
///
[DllImport(DllName, EntryPoint="bgfx_vertex_decl_add", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe VertexDecl* vertex_decl_add(VertexDecl* _this, Attrib _attrib, byte _num, AttribType _type, byte _normalized, byte _asInt);
+ public static extern unsafe VertexDecl* vertex_decl_add(VertexDecl* _this, Attrib _attrib, byte _num, AttribType _type, bool _normalized, bool _asInt);
///
/// Decode attribute.
@@ -935,7 +935,7 @@ public static partial class bgfx
/// Attribute is packed as int.
///
[DllImport(DllName, EntryPoint="bgfx_vertex_decl_decode", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void vertex_decl_decode(VertexDecl* _this, Attrib _attrib, byte * _num, AttribType* _type, byte * _normalized, byte * _asInt);
+ public static extern unsafe void vertex_decl_decode(VertexDecl* _this, Attrib _attrib, byte * _num, AttribType* _type, bool* _normalized, bool* _asInt);
///
/// Returns true if VertexDecl contains attribute.
@@ -945,7 +945,7 @@ public static partial class bgfx
///
[DllImport(DllName, EntryPoint="bgfx_vertex_decl_has", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
- public static extern unsafe byte vertex_decl_has(VertexDecl* _this, Attrib _attrib);
+ public static extern unsafe bool vertex_decl_has(VertexDecl* _this, Attrib _attrib);
///
/// Skip `_num` bytes in vertex stream.
@@ -973,7 +973,7 @@ public static partial class bgfx
/// Vertex index that will be modified.
///
[DllImport(DllName, EntryPoint="bgfx_vertex_pack", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void vertex_pack(float _input, byte _inputNormalized, Attrib _attr, VertexDecl* _decl, void* _data, uint _index);
+ public static extern unsafe void vertex_pack(float _input, bool _inputNormalized, Attrib _attr, VertexDecl* _decl, void* _data, uint _index);
///
/// Unpack vertex attribute from vertex stream format.
@@ -1026,7 +1026,7 @@ public static partial class bgfx
/// Set to `true` if input indices are 32-bit.
///
[DllImport(DllName, EntryPoint="bgfx_topology_convert", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe uint topology_convert(TopologyConvert _conversion, void* _dst, uint _dstSize, void* _indices, uint _numIndices, byte _index32);
+ public static extern unsafe uint topology_convert(TopologyConvert _conversion, void* _dst, uint _dstSize, void* _indices, uint _numIndices, bool _index32);
///
/// Sort indices.
@@ -1044,7 +1044,7 @@ public static partial class bgfx
/// Set to `true` if input indices are 32-bit.
///
[DllImport(DllName, EntryPoint="bgfx_topology_sort_tri_list", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void topology_sort_tri_list(TopologySort _sort, void* _dst, uint _dstSize, float _dir, float _pos, void* _vertices, uint _stride, void* _indices, uint _numIndices, byte _index32);
+ public static extern unsafe void topology_sort_tri_list(TopologySort _sort, void* _dst, uint _dstSize, float _dir, float _pos, void* _vertices, uint _stride, void* _indices, uint _numIndices, bool _index32);
///
/// Returns supported backend API renderers.
@@ -1076,7 +1076,7 @@ public static partial class bgfx
///
[DllImport(DllName, EntryPoint="bgfx_init", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
- public static extern unsafe byte init(Init* _init);
+ public static extern unsafe bool init(Init* _init);
///
/// Shutdown bgfx library.
@@ -1108,7 +1108,7 @@ public static partial class bgfx
/// Capture frame with graphics debugger.
///
[DllImport(DllName, EntryPoint="bgfx_frame", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe uint frame(byte _capture);
+ public static extern unsafe uint frame(bool _capture);
///
/// Returns current renderer backend API type.
@@ -1206,7 +1206,7 @@ public static partial class bgfx
/// Default 8x16 or 8x8 font.
///
[DllImport(DllName, EntryPoint="bgfx_dbg_text_clear", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void dbg_text_clear(byte _attr, byte _small);
+ public static extern unsafe void dbg_text_clear(byte _attr, bool _small);
///
/// Print formatted data to internal debug text character-buffer (VGA-compatible text mode).
@@ -1476,7 +1476,7 @@ public static partial class bgfx
///
[DllImport(DllName, EntryPoint="bgfx_alloc_transient_buffers", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
- public static extern unsafe byte alloc_transient_buffers(TransientVertexBuffer* _tvb, VertexDecl* _decl, uint _numVertices, TransientIndexBuffer* _tib, uint _numIndices);
+ public static extern unsafe bool alloc_transient_buffers(TransientVertexBuffer* _tvb, VertexDecl* _decl, uint _numVertices, TransientIndexBuffer* _tib, uint _numIndices);
///
/// Allocate instance data buffer.
@@ -1560,7 +1560,7 @@ public static partial class bgfx
/// If true, shaders will be destroyed when program is destroyed.
///
[DllImport(DllName, EntryPoint="bgfx_create_program", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe ProgramHandle create_program(ShaderHandle _vsh, ShaderHandle _fsh, byte _destroyShaders);
+ public static extern unsafe ProgramHandle create_program(ShaderHandle _vsh, ShaderHandle _fsh, bool _destroyShaders);
///
/// Create program with compute shader.
@@ -1570,7 +1570,7 @@ public static partial class bgfx
/// If true, shaders will be destroyed when program is destroyed.
///
[DllImport(DllName, EntryPoint="bgfx_create_compute_program", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe ProgramHandle create_compute_program(ShaderHandle _csh, byte _destroyShaders);
+ public static extern unsafe ProgramHandle create_compute_program(ShaderHandle _csh, bool _destroyShaders);
///
/// Destroy program.
@@ -1593,7 +1593,7 @@ public static partial class bgfx
///
[DllImport(DllName, EntryPoint="bgfx_is_texture_valid", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
- public static extern unsafe byte is_texture_valid(ushort _depth, byte _cubeMap, ushort _numLayers, TextureFormat _format, ulong _flags);
+ public static extern unsafe bool is_texture_valid(ushort _depth, bool _cubeMap, ushort _numLayers, TextureFormat _format, ulong _flags);
///
/// Calculate amount of memory required for texture.
@@ -1609,7 +1609,7 @@ public static partial class bgfx
/// Texture format. See: `TextureFormat::Enum`.
///
[DllImport(DllName, EntryPoint="bgfx_calc_texture_size", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void calc_texture_size(TextureInfo* _info, ushort _width, ushort _height, ushort _depth, byte _cubeMap, byte _hasMips, ushort _numLayers, TextureFormat _format);
+ public static extern unsafe void calc_texture_size(TextureInfo* _info, ushort _width, ushort _height, ushort _depth, bool _cubeMap, bool _hasMips, ushort _numLayers, TextureFormat _format);
///
/// Create texture from memory buffer.
@@ -1636,7 +1636,7 @@ public static partial class bgfx
/// Texture data. If `_mem` is non-NULL, created texture will be immutable. If `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than 1, expected memory layout is texture and all mips together for each array element.
///
[DllImport(DllName, EntryPoint="bgfx_create_texture_2d", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe TextureHandle create_texture_2d(ushort _width, ushort _height, byte _hasMips, ushort _numLayers, TextureFormat _format, ulong _flags, Memory* _mem);
+ public static extern unsafe TextureHandle create_texture_2d(ushort _width, ushort _height, bool _hasMips, ushort _numLayers, TextureFormat _format, ulong _flags, Memory* _mem);
///
/// Create texture with size based on backbuffer ratio. Texture will maintain ratio
@@ -1650,7 +1650,7 @@ public static partial class bgfx
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
///
[DllImport(DllName, EntryPoint="bgfx_create_texture_2d_scaled", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe TextureHandle create_texture_2d_scaled(BackbufferRatio _ratio, byte _hasMips, ushort _numLayers, TextureFormat _format, ulong _flags);
+ public static extern unsafe TextureHandle create_texture_2d_scaled(BackbufferRatio _ratio, bool _hasMips, ushort _numLayers, TextureFormat _format, ulong _flags);
///
/// Create 3D texture.
@@ -1665,7 +1665,7 @@ public static partial class bgfx
/// Texture data. If `_mem` is non-NULL, created texture will be immutable. If `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than 1, expected memory layout is texture and all mips together for each array element.
///
[DllImport(DllName, EntryPoint="bgfx_create_texture_3d", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe TextureHandle create_texture_3d(ushort _width, ushort _height, ushort _depth, byte _hasMips, TextureFormat _format, ulong _flags, Memory* _mem);
+ public static extern unsafe TextureHandle create_texture_3d(ushort _width, ushort _height, ushort _depth, bool _hasMips, TextureFormat _format, ulong _flags, Memory* _mem);
///
/// Create Cube texture.
@@ -1679,7 +1679,7 @@ public static partial class bgfx
/// Texture data. If `_mem` is non-NULL, created texture will be immutable. If `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than 1, expected memory layout is texture and all mips together for each array element.
///
[DllImport(DllName, EntryPoint="bgfx_create_texture_cube", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe TextureHandle create_texture_cube(ushort _size, byte _hasMips, ushort _numLayers, TextureFormat _format, ulong _flags, Memory* _mem);
+ public static extern unsafe TextureHandle create_texture_cube(ushort _size, bool _hasMips, ushort _numLayers, TextureFormat _format, ulong _flags, Memory* _mem);
///
/// Update 2D texture.
@@ -1813,7 +1813,7 @@ public static partial class bgfx
/// If true, textures will be destroyed when frame buffer is destroyed.
///
[DllImport(DllName, EntryPoint="bgfx_create_frame_buffer_from_handles", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe FrameBufferHandle create_frame_buffer_from_handles(byte _num, TextureHandle* _handles, byte _destroyTexture);
+ public static extern unsafe FrameBufferHandle create_frame_buffer_from_handles(byte _num, TextureHandle* _handles, bool _destroyTexture);
///
/// Create MRT frame buffer from texture handles with specific layer and
@@ -1825,7 +1825,7 @@ public static partial class bgfx
/// If true, textures will be destroyed when frame buffer is destroyed.
///
[DllImport(DllName, EntryPoint="bgfx_create_frame_buffer_from_attachment", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe FrameBufferHandle create_frame_buffer_from_attachment(byte _num, Attachment* _attachment, byte _destroyTexture);
+ public static extern unsafe FrameBufferHandle create_frame_buffer_from_attachment(byte _num, Attachment* _attachment, bool _destroyTexture);
///
/// Create frame buffer for multiple window rendering.
@@ -2115,7 +2115,7 @@ public static partial class bgfx
/// Explicitly request an encoder for a worker thread.
///
[DllImport(DllName, EntryPoint="bgfx_encoder_begin", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe Encoder* encoder_begin(byte _forThread);
+ public static extern unsafe Encoder* encoder_begin(bool _forThread);
///
/// End submitting draw calls from thread.
@@ -2164,7 +2164,7 @@ public static partial class bgfx
/// Render if occlusion query is visible.
///
[DllImport(DllName, EntryPoint="bgfx_encoder_set_condition", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void encoder_set_condition(Encoder* _this, OcclusionQueryHandle _handle, byte _visible);
+ public static extern unsafe void encoder_set_condition(Encoder* _this, OcclusionQueryHandle _handle, bool _visible);
///
/// Set stencil test state.
@@ -2403,7 +2403,7 @@ public static partial class bgfx
/// Preserve internal draw state for next draw call submit.
///
[DllImport(DllName, EntryPoint="bgfx_encoder_submit", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void encoder_submit(Encoder* _this, ushort _id, ProgramHandle _program, uint _depth, byte _preserveState);
+ public static extern unsafe void encoder_submit(Encoder* _this, ushort _id, ProgramHandle _program, uint _depth, bool _preserveState);
///
/// Submit primitive with occlusion query for rendering.
@@ -2416,7 +2416,7 @@ public static partial class bgfx
/// Preserve internal draw state for next draw call submit.
///
[DllImport(DllName, EntryPoint="bgfx_encoder_submit_occlusion_query", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void encoder_submit_occlusion_query(Encoder* _this, ushort _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint _depth, byte _preserveState);
+ public static extern unsafe void encoder_submit_occlusion_query(Encoder* _this, ushort _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint _depth, bool _preserveState);
///
/// Submit primitive for rendering with index and instance data info from
@@ -2432,7 +2432,7 @@ public static partial class bgfx
/// Preserve internal draw state for next draw call submit.
///
[DllImport(DllName, EntryPoint="bgfx_encoder_submit_indirect", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void encoder_submit_indirect(Encoder* _this, ushort _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, ushort _start, ushort _num, uint _depth, byte _preserveState);
+ public static extern unsafe void encoder_submit_indirect(Encoder* _this, ushort _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, ushort _start, ushort _num, uint _depth, bool _preserveState);
///
/// Set compute index buffer.
@@ -2680,7 +2680,7 @@ public static partial class bgfx
/// Render if occlusion query is visible.
///
[DllImport(DllName, EntryPoint="bgfx_set_condition", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void set_condition(OcclusionQueryHandle _handle, byte _visible);
+ public static extern unsafe void set_condition(OcclusionQueryHandle _handle, bool _visible);
///
/// Set stencil test state.
@@ -2916,7 +2916,7 @@ public static partial class bgfx
/// Preserve internal draw state for next draw call submit.
///
[DllImport(DllName, EntryPoint="bgfx_submit", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void submit(ushort _id, ProgramHandle _program, uint _depth, byte _preserveState);
+ public static extern unsafe void submit(ushort _id, ProgramHandle _program, uint _depth, bool _preserveState);
///
/// Submit primitive with occlusion query for rendering.
@@ -2929,7 +2929,7 @@ public static partial class bgfx
/// Preserve internal draw state for next draw call submit.
///
[DllImport(DllName, EntryPoint="bgfx_submit_occlusion_query", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void submit_occlusion_query(ushort _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint _depth, byte _preserveState);
+ public static extern unsafe void submit_occlusion_query(ushort _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint _depth, bool _preserveState);
///
/// Submit primitive for rendering with index and instance data info from
@@ -2945,7 +2945,7 @@ public static partial class bgfx
/// Preserve internal draw state for next draw call submit.
///
[DllImport(DllName, EntryPoint="bgfx_submit_indirect", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void submit_indirect(ushort _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, ushort _start, ushort _num, uint _depth, byte _preserveState);
+ public static extern unsafe void submit_indirect(ushort _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, ushort _start, ushort _num, uint _depth, bool _preserveState);
///
/// Set compute index buffer.
diff --git a/scripts/bindings-cs.lua b/scripts/bindings-cs.lua
index b8f482912..b53d228e9 100644
--- a/scripts/bindings-cs.lua
+++ b/scripts/bindings-cs.lua
@@ -15,7 +15,6 @@ local csharp_template = [[
using System;
using System.Runtime.InteropServices;
-using System.Security;
namespace Bgfx
{
@@ -60,8 +59,6 @@ local function convert_type_0(arg)
return arg.ctype:gsub("bgfx_view_id_t", "ushort")
elseif hasPrefix(arg.ctype, "uint8_t") then
return arg.ctype:gsub("uint8_t", "byte")
- elseif hasPrefix(arg.ctype, "bool") then
- return arg.ctype:gsub("bool", "byte")
elseif hasPrefix(arg.ctype, "uintptr_t") then
return arg.ctype:gsub("uintptr_t", "UIntPtr")
elseif arg.ctype == "bgfx_caps_gpu_t" then
@@ -87,8 +84,7 @@ local function convert_type_0(arg)
end
local function convert_type(arg)
- local ctype;
- ctype = convert_type_0(arg)
+ local ctype = convert_type_0(arg)
ctype = ctype:gsub("::Enum", "")
ctype = ctype:gsub("const ", "")
ctype = ctype:gsub(" &", "*")
@@ -96,12 +92,19 @@ local function convert_type(arg)
return ctype
end
+local function convert_struct_type(arg)
+ local ctype = convert_type(arg)
+ if hasPrefix(arg.ctype, "bool") then
+ ctype = ctype:gsub("bool", "byte")
+ end
+ return ctype
+end
+
local function convert_ret_type(arg)
local ctype = convert_type(arg)
if hasPrefix(ctype, "[MarshalAs(UnmanagedType.LPStr)]") then
return "IntPtr"
end
-
return ctype
end
@@ -214,9 +217,9 @@ end
local function convert_struct_member(member)
if member.array then
- return "fixed " .. convert_type(member) .. " " .. member.name .. convert_array(member)
+ return "fixed " .. convert_struct_type(member) .. " " .. member.name .. convert_array(member)
else
- return convert_type(member) .. " " .. member.name
+ return convert_struct_type(member) .. " " .. member.name
end
end