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
This commit is contained in:
Sebastian Marketsmueller 2019-07-10 21:27:03 -07:00 committed by Бранимир Караџић
parent a6fc055d03
commit e938ddf88c
2 changed files with 40 additions and 37 deletions

View File

@ -922,7 +922,7 @@ public static partial class bgfx
/// <param name="_asInt">Packaging rule for vertexPack, vertexUnpack, and vertexConvert for AttribType::Uint8 and AttribType::Int16. Unpacking code must be implemented inside vertex shader.</param>
///
[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);
/// <summary>
/// Decode attribute.
@ -935,7 +935,7 @@ public static partial class bgfx
/// <param name="_asInt">Attribute is packed as int.</param>
///
[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);
/// <summary>
/// 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);
/// <summary>
/// Skip `_num` bytes in vertex stream.
@ -973,7 +973,7 @@ public static partial class bgfx
/// <param name="_index">Vertex index that will be modified.</param>
///
[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);
/// <summary>
/// Unpack vertex attribute from vertex stream format.
@ -1026,7 +1026,7 @@ public static partial class bgfx
/// <param name="_index32">Set to `true` if input indices are 32-bit.</param>
///
[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);
/// <summary>
/// Sort indices.
@ -1044,7 +1044,7 @@ public static partial class bgfx
/// <param name="_index32">Set to `true` if input indices are 32-bit.</param>
///
[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);
/// <summary>
/// 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);
/// <summary>
/// Shutdown bgfx library.
@ -1108,7 +1108,7 @@ public static partial class bgfx
/// <param name="_capture">Capture frame with graphics debugger.</param>
///
[DllImport(DllName, EntryPoint="bgfx_frame", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe uint frame(byte _capture);
public static extern unsafe uint frame(bool _capture);
/// <summary>
/// Returns current renderer backend API type.
@ -1206,7 +1206,7 @@ public static partial class bgfx
/// <param name="_small">Default 8x16 or 8x8 font.</param>
///
[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);
/// <summary>
/// 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);
/// <summary>
/// Allocate instance data buffer.
@ -1560,7 +1560,7 @@ public static partial class bgfx
/// <param name="_destroyShaders">If true, shaders will be destroyed when program is destroyed.</param>
///
[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);
/// <summary>
/// Create program with compute shader.
@ -1570,7 +1570,7 @@ public static partial class bgfx
/// <param name="_destroyShaders">If true, shaders will be destroyed when program is destroyed.</param>
///
[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);
/// <summary>
/// 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);
/// <summary>
/// Calculate amount of memory required for texture.
@ -1609,7 +1609,7 @@ public static partial class bgfx
/// <param name="_format">Texture format. See: `TextureFormat::Enum`.</param>
///
[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);
/// <summary>
/// Create texture from memory buffer.
@ -1636,7 +1636,7 @@ public static partial class bgfx
/// <param name="_mem">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.</param>
///
[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);
/// <summary>
/// Create texture with size based on backbuffer ratio. Texture will maintain ratio
@ -1650,7 +1650,7 @@ public static partial class bgfx
/// <param name="_flags">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.</param>
///
[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);
/// <summary>
/// Create 3D texture.
@ -1665,7 +1665,7 @@ public static partial class bgfx
/// <param name="_mem">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.</param>
///
[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);
/// <summary>
/// Create Cube texture.
@ -1679,7 +1679,7 @@ public static partial class bgfx
/// <param name="_mem">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.</param>
///
[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);
/// <summary>
/// Update 2D texture.
@ -1813,7 +1813,7 @@ public static partial class bgfx
/// <param name="_destroyTexture">If true, textures will be destroyed when frame buffer is destroyed.</param>
///
[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);
/// <summary>
/// Create MRT frame buffer from texture handles with specific layer and
@ -1825,7 +1825,7 @@ public static partial class bgfx
/// <param name="_destroyTexture">If true, textures will be destroyed when frame buffer is destroyed.</param>
///
[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);
/// <summary>
/// Create frame buffer for multiple window rendering.
@ -2115,7 +2115,7 @@ public static partial class bgfx
/// <param name="_forThread">Explicitly request an encoder for a worker thread.</param>
///
[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);
/// <summary>
/// End submitting draw calls from thread.
@ -2164,7 +2164,7 @@ public static partial class bgfx
/// <param name="_visible">Render if occlusion query is visible.</param>
///
[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);
/// <summary>
/// Set stencil test state.
@ -2403,7 +2403,7 @@ public static partial class bgfx
/// <param name="_preserveState">Preserve internal draw state for next draw call submit.</param>
///
[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);
/// <summary>
/// Submit primitive with occlusion query for rendering.
@ -2416,7 +2416,7 @@ public static partial class bgfx
/// <param name="_preserveState">Preserve internal draw state for next draw call submit.</param>
///
[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);
/// <summary>
/// Submit primitive for rendering with index and instance data info from
@ -2432,7 +2432,7 @@ public static partial class bgfx
/// <param name="_preserveState">Preserve internal draw state for next draw call submit.</param>
///
[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);
/// <summary>
/// Set compute index buffer.
@ -2680,7 +2680,7 @@ public static partial class bgfx
/// <param name="_visible">Render if occlusion query is visible.</param>
///
[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);
/// <summary>
/// Set stencil test state.
@ -2916,7 +2916,7 @@ public static partial class bgfx
/// <param name="_preserveState">Preserve internal draw state for next draw call submit.</param>
///
[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);
/// <summary>
/// Submit primitive with occlusion query for rendering.
@ -2929,7 +2929,7 @@ public static partial class bgfx
/// <param name="_preserveState">Preserve internal draw state for next draw call submit.</param>
///
[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);
/// <summary>
/// Submit primitive for rendering with index and instance data info from
@ -2945,7 +2945,7 @@ public static partial class bgfx
/// <param name="_preserveState">Preserve internal draw state for next draw call submit.</param>
///
[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);
/// <summary>
/// Set compute index buffer.

View File

@ -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